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

Reply via email to