0

I have the strangest error I have seen for a while in Python (version 3.0).

Changing the signature of the function affects whether super() works, despite the fact that it takes no arguments. Can you explain why this occurs?

Thanks,

Chris

>>> class tmp:
...     def __new__(*args):
...             super()
... 
>>> tmp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __new__
SystemError: super(): no arguments
>>> class tmp:
...     def __new__(mcl,*args):
...             super()
... 
>>> tmp()
>>>

2 Answers 2

6

As the docs say, "The zero argument form automatically searches the stack frame for the class (__class__) and the first argument." Your first example of __new__ doesn't HAVE a first argument - it claims it can be called with zero or more arguments, so argumentless super is stumped. Your second example DOES have an explicit first argument, so the search in the stack frame succeeds.

1

python 3.0 new super is trying to dynamically make a choice for you here, read this PEP here that should explain everything.

Not the answer you're looking for? Browse other questions tagged or ask your own question.