You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Setting __module__ doesn't remove __firstlineno__ when the class has a custom metaclass #162572
The docs say "Setting the __module__ attribute removes the __firstlineno__ item from the type's dictionary" (type.__firstlineno__). For a class whose metaclass is written in Python (abc.ABC, enum.Enum, class M(type): pass) it stays, so inspect.getsource returns lines of the module named by the new __module__, the problem of gh-123339:
P False OSError source code not available
A True 'This module encapsulates the interface p'
The metaclass's own __module__ string in its __dict__ comes before the __module__ descriptor of type in the lookup, so the assignment just stores into the class's __dict__ and type_set_module (Objects/typeobject.c), which removes __firstlineno__, never runs. I found it while writing a Lean spec of Python.
Activity