views:

179

answers:

2

Hi all,

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()
>>>
+1  A: 

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

Chmouel Boudjnah
+5  A: 

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.

Alex Martelli