osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From parsing a class to code object to class to mappingproxy to object (oh my!)


On Monday, April 1, 2019 at 1:23:42 AM UTC-5, Gregory Ewing wrote:
> adam.preble at gmail.com wrote:
> https://eli.thegreenplace.net/2012/06/15/under-the-hood-of-python-class-definitions
> 
> Briefly, it creates a dict to serve as the class's namespace dict,
> then executes the class body function passed to it, with that dict
> as the local namespace. So method defs and other assignments go
> straight into what will become the class namespace when the class
> object is created.

Thanks for the response. I was meaning to write back earlier, but I've been spending my free Python time in the evenings reimplementing what I'm doing to work more correctly. I'm guessing before the code object representing the class body gets run, __build_class__ is establishing various dunders such as __name__, __qual_name__, and __module__. I haven't fully penetrated that, but I also took an embarrassingly long amount of time to fully comprehend LOAD_NAME versus LOAD_FAST versus LOAD_GLOBAL...