views:

44

answers:

2

I'd like to subclass an existing scons class (named SConsEnvironment) which has the following __init__ prototype:

 def __init__(self,
                 platform=None,
                 tools=None,
                 toolpath=None,
                 variables=None,
                 parse_flags = None,
                 **kw):

In my own class Environment, which derives from SConsEnvironment, I tried to do:

def __init__(self,
             platform=None,
             tools=None,
             toolpath=None,
             variables=None,
             parse_flags = None,
             **kw):

    if ('ENV' not in kw):
        kw['ENV'] = os.environ.copy()

    super(EIDEnvironment, self).__init__(
            platform,
            tools,
            toolpath,
            variables,
            parse_flags,
            kw) //Error here

Python complains:

TypeError: __init__() takes at most 6 arguments (7 given):

Unless I don't know how to count anymore, it seems that both __init__ functions take 7 arguments. I'm sure there is a good reason for this not to work, but what is it and how can I solve this ?

+3  A: 

In the super(EIDEnvironment, self).__init__(...) call, change kw to **kw. As the code is currently written, you're passing a dictionary containing the keyword args, but not actually passing them as keyword args.

Doug
Works like a charm ! Many thanks.
ereOn
+1  A: 

I guess you need to unpack kw otherwise you pass it as a dictionary:

super(EIDEnvironment, self).__init__(
            platform,
            tools,
            toolpath,
            variables,
            parse_flags,
            **kw)
slosd