Skip to content

gh-162572: Remove __firstlineno__ when __module__ is set through a metaclass attribute - #162957

Open
Chetansahney wants to merge 3 commits into
python:mainfrom
Chetansahney:gh-162572-module-firstlineno-metaclass
Open

Chetansahney wants to merge 3 commits into
python:mainfrom
Chetansahney:gh-162572-module-firstlineno-metaclass

Conversation

@Chetansahney

Copy link
Copy Markdown

When the metaclass has a __module__ attribute (any metaclass defined in Python, e.g. abc.ABCMeta or enum.EnumType), type_setattro finds that plain string before the type.__module__ getset descriptor, so assigning cls.__module__ stores into the class dict directly and type_set_module, which removes __firstlineno__, never runs.

type_setattro now also removes __firstlineno__ after setting __module__ through the class dict. A metaclass that defines __module__ as a data descriptor is unaffected, since the assignment still goes to that descriptor.

Tested with python -m test test_builtin test_descr test_inspect test_abc test_enum test_types on a debug build (Windows); the new test fails without the change.

@python-cla-bot

python-cla-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@Chetansahney
Chetansahney force-pushed the gh-162572-module-firstlineno-metaclass branch from c2a976c to fd890e5 Compare December 3, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant