Skip to content

Fix collections.namedtuple not recognized when collections.abc is imported#2671

Open
yangdanny97 wants to merge 1 commit intofacebook:mainfrom
yangdanny97:export-D95422174
Open

Fix collections.namedtuple not recognized when collections.abc is imported#2671
yangdanny97 wants to merge 1 commit intofacebook:mainfrom
yangdanny97:export-D95422174

Conversation

@yangdanny97
Copy link
Contributor

Summary:
When import collections.abc follows import collections, the flow style for the name collections was overwritten with MergeableImport("collections.abc"). This caused as_special_export to check is_special_export("collections.abc", "namedtuple"), which failed because CollectionsNamedTuple.defined_in() only matches "collections".

Fix: for MergeableImport, use the bound name (which is always the first component of the dotted import path) as the module name for special export checking, instead of the stored full dotted path.

Fixes #2622

Differential Revision: D95422174

…orted

Summary:
When `import collections.abc` follows `import collections`, the flow style for the name `collections` was overwritten with `MergeableImport("collections.abc")`. This caused `as_special_export` to check `is_special_export("collections.abc", "namedtuple")`, which failed because `CollectionsNamedTuple.defined_in()` only matches `"collections"`.

Fix: for `MergeableImport`, use the bound name (which is always the first component of the dotted import path) as the module name for special export checking, instead of the stored full dotted path.

Fixes facebook#2622

Differential Revision: D95422174
@meta-cla meta-cla bot added the cla signed label Mar 5, 2026
@meta-codesync
Copy link

meta-codesync bot commented Mar 5, 2026

@yangdanny97 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D95422174.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

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 breakage in namedtuple() handling

2 participants