Petr Viktorin <[email protected]> added the comment:
> only if PEP 573 makes it *compulsory* for heap types to contain a pointer to
> their module
And that's impossible without either breaking API (or some hackery).
PyType_FromSpec doesn't get the information, and it can be easily outside
module initialization.
One possibility is to attach the __main__ module (or sys, or some synthetic
module) to "module-less" classes, just to have something interpreter-specific
there. But at that point, a dedicated "PyInterpreterState *" field starts
looking like a better alternative.
It does complicate the "chain":
instance --> type -?> module --> interpreter
| ^
'-------------------'
But, one more thing that we need to think about is static types. Those are
shared across interpreters; the "PyInterpreterState *" field should only be
added to PyHeapTypeObject. ISTM that until we phase out static types entirely,
you can't get the interpreter by following pointers from a type/instance anyway.
At that point, the opt-in approach of PEP 573 starts looking more attractive
again:
instance --> type -?> module --> interpreter
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38160>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com