How would the interpreter know which 
Class the rebound “belonged” to? 

For example, that same function could be added to two different classes— then what would super() do? 

BTW, the Python 2 style of calling súper with the class and instance as arguments might work in the case :-)

As an experiment, try adding the placement method to a different class altogether and see what you get.

class another:
    foo = child.placement

-CHB



On Tue, Jul 27, 2021 at 8:16 PM Yua <uncha21@163.com> wrote:
For example, the following code would report an error:

    class base():
         def foo(self) -> None:
             print('Base!')

    def placement(self) -> None:
         super().foo()

    class child(base):
         def foo(self) -> None:
             pass
         foo = placement

    child().foo()

RuntimeError: super(): __class__ cell not found


However, it would be OK if `placement` is defined inside the class:

    class base():
         def foo(self) -> None:
             print('Base!')

    class child(base):
         def placement(self) -> None:
             super().foo()
         def foo(self) -> None:
             pass
         foo = placement

    child().foo()

which prints:

    Base!


I think it would be natural if those functions that was defined outside
a class, but then rebound into a class, can see magic variables like
__class__ that are only shared by those functions defined inside a class.


Thank you!


_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/GTTD2CSWNCSH2UW657YK3M7GPSUOKWYS/
Code of Conduct: http://python.org/psf/codeofconduct/
--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython