2

Consider the following example:

class Base:
    def b(self):
        pass
    
class Derived(Base):
    def b(self):
        super().b()
    def d(self):
        pass
    
Derived.b.__closure__
Out[4]: (<cell at 0x7f9664103610: type object at 0x7f965dd8c2b0>,)
Derived.d.__closure__

Derived.b.__closure__[0].cell_contents
Out[6]: __main__.Derived

I wish to understand the following:

  • Why does Derived.b contains a closure and Derived.d not
  • What happening behind the scenes? explanation of Derived.b cell_contents result
  • Is using the cell_contents result is a possible way to detect that a method called super() ?

Thanks!

aikiOr
  • 51
  • 3
  • This is all explained over at [Schrödinger's variable: the `__class__` cell magically appears if you're checking for its presence?](https://stackoverflow.com/q/36993577/674039). TL;DR - yes, it's a special-case check for usage of the name "super" at compile time – wim Jan 19 '22 at 13:11

0 Answers0