On Wed, Apr 06, 2022 at 02:47:57AM +1200, Greg Ewing wrote:

> I think you misunderstand the reason why super() accepts a class
> argument.
> 
> It's purely for historical reasons.

No, it is because it actually does need to know which class it is being 
called from, as well as the object that originated the call.


> Originally super() couldn't
> tell on its own which class it was being called from, and had
> to be told.

And it still does. The only difference is that now, in Python 3, the 
interpreter is able to automatically tell it. It does that by giving 
methods a special cell variable called "__class__" that references the 
class they belong to. See PEP 3135.

https://peps.python.org/pep-3135/


> It's only there now for backwards compatibility. 

No, sometimes you still have to explicitly pass the arguments yourself, 
if the interpreter can't work it out.


> It's not intended for picking and choosing which class to target --
> that's what explicit class.method calls are for.

I agree with that, but as always, if you know what you are doing, you 
can use a tool for a completely unexpected purpose.

If you know what you are doing.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GWBTUOJGVPCONBMVPZV7GXFBRM4HBVBJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to