On Wed, 6 Apr 2022 at 08:42, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
>
> On 6/04/22 4:57 am, Eric Fahlgren wrote:
> > On Tue, Apr 5, 2022 at 7:49 AM Greg Ewing <greg.ew...@canterbury.ac.nz
> > <mailto:greg.ew...@canterbury.ac.nz>> wrote:
>  >
> >     It's only there now for backwards compatibility.
> >
> > Not always.  I have an example, where a method creates a closure that
> > calls super, requiring the class/self pair as there isn't enough context
> > for parameterless super.
>
> Fair point, but you're still using it to keep track of the class
> defining the method concerned, not to target some other class
> in the MRO.
>
> BTW, it seems to me that such a closure should also participate
> in the magic behind argumentless super. Seems like it should be
> possible.
>

It would be able to reference __class__, but the other part of
argumentless super is "the first argument to this function" (the one
conventionally named 'self'), so in an argless closure, that won't
work. Passing self to the closure does seem to work.

>>> class X:
...     def spam(self):
...             def cl(self):
...                     print(super())
...             cl(self)
>>> X().spam()
<super: <class 'X'>, <X object>>

ChrisA
_______________________________________________
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/A6YUAASRPWVMFAR4Z3YCZ2M6NSBPGGOT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to