[Python-Dev] PEP 573 -- Module State Access from C Extension Methods

Petr Viktorin encukou at gmail.com
Wed Apr 25 15:04:36 EDT 2018


On 04/25/18 14:46, Jeroen Demeyer wrote:
> On 2018-04-25 20:33, Petr Viktorin wrote:
>> Perhaps "m_objclass" could point to the module in this case
> 
> That was exactly my idea also today. Instead of treating m_objclass as 
> the defining class, we should generalize it to be the "parent" of the 
> function: either the class or the module.

Great to hear we think alike.

However, I think that while reusing the pointer is nice to save space, 
the two concepts should still be separate, because "defining module" is 
a reasonable concept even for methods. In particular:
- There should be *separate* accessor functions for:
   - getting the defining class
   - getting the defining module
- The latter would later (in PEP 573) be extended to return the defining 
module even for class methods (when available)
- In Python code, __objclass__ should be the defining class, not the module.
- The C field should have a different name (m_parent?), so it isn't that 
strongly associated with __objclass__.

Does that sound reasonable?


More information about the Python-Dev mailing list