From parsing a class to code object to class to mappingproxy to object (oh my!)
greg.ewing at canterbury.ac.nz
Sat Apr 6 07:59:06 EDT 2019
adam.preble at gmail.com wrote:
> I've figured from this that I could do most
> variable access by just generating LOAD/STORE_NAME and the FAST is an
> (important) optimization.
Yes, that's possible, although access to intermediate scopes
(i.e. nonlocal) will need something else.
> important exception there would be for built-ins and presumably imported
> stuff, right?
No, importing things just binds names in your module namespace,
so LOAD_GLOBAL does for them too. Also builtins, since if
LOAD_GLOBAL doesn't find something in the module namespace,
it looks in the builtins.
> I'm asking because right now I've literally hard-coded some logic that tells
> me if I'm generating a class body so I know to use names. I just feel kind of
> silly doing that.
There's nothing silly about that -- it's effectively what CPython
More information about the Python-list