Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-127187: Set correct __module__ attribute for methods of named tuple types #127188

Closed
wants to merge 9 commits into from

Conversation

XuehaiPan
Copy link
Contributor

@XuehaiPan XuehaiPan commented Nov 23, 2024

Set correct __module__ attribute for methods of named tuple types.

Fixes #127187

@rhettinger rhettinger self-assigned this Nov 23, 2024
method.__qualname__ = f'{typename}.{method.__name__}'
if module is not None:
method.__module__ = module
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need to check module is a str object. In the test, the module argument can be passed with collections (an instance of ModuleType).

@rhettinger rhettinger closed this Nov 27, 2024
@XuehaiPan
Copy link
Contributor Author

XuehaiPan commented Nov 27, 2024

I think this PR is still valuable. It avoids potential bugs if there is a namedtuple_xxx module (e.g. namedtuple_tests.py in the local directory). Also, dataclasses.dataclass generates methods with appropriate __module__ set while typing.NamedTuple does not.

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.

Unexpected __module__ attribute for NamedTupleType.__new__ method: namedtuple_{typename}
2 participants