Skip to content

Narrowing for comparisons against x.__class__ - #20642

Merged
JukkaL merged 1 commit into
python:masterfrom
hauntsaninja:narrow21
Jan 26, 2026
Merged

Narrowing for comparisons against x.__class__#20642
JukkaL merged 1 commit into
python:masterfrom
hauntsaninja:narrow21

Conversation

@hauntsaninja

Copy link
Copy Markdown
Collaborator

No description provided.

@hauntsaninjahauntsaninja mentioned this pull request Jan 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

beartype (https://github.com/beartype/beartype)
+ beartype/_util/hint/pep/utilpepsign.py:592: error: Unused "type: ignore" comment [unused-ignore]
black (https://github.com/psf/black)
+ src/blib2to3/pytree.py:84:9: error: Returning Any from function declared to return "bool" [no-any-return]
static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/util.py:2085: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/util.py:2087: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/util.py:2089: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/util.py:2095: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/util.py:2096: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/util.py:2186: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/util.py:2188: error: Unused "type: ignore" comment [unused-ignore]- static_frame/core/util.py:2307: error: "Hashable" has no attribute "start" [attr-defined]- static_frame/core/util.py:2307: note: Error code "attr-defined" not covered by "type: ignore" comment- static_frame/core/util.py:2309: error: "Hashable" has no attribute "stop" [attr-defined]- static_frame/core/util.py:2309: note: Error code "attr-defined" not covered by "type: ignore" comment- static_frame/core/util.py:2310: error: "Hashable" has no attribute "stop" [attr-defined]- static_frame/core/util.py:2310: note: Error code "attr-defined" not covered by "type: ignore" comment- static_frame/core/util.py:2311: error: "Hashable" has no attribute "step" [attr-defined]- static_frame/core/util.py:2311: note: Error code "attr-defined" not covered by "type: ignore" comment- static_frame/core/util.py:2312: error: "Hashable" has no attribute "step" [attr-defined]- static_frame/core/util.py:2312: note: Error code "attr-defined" not covered by "type: ignore" comment+ static_frame/core/loc_map.py:157: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/loc_map.py:169: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/loc_map.py:171: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/loc_map.py:174: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/loc_map.py:176: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/loc_map.py:177: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/node_fill_value.py:126: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/container_util.py:1065: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/container_util.py:1526: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/container_util.py:1528: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/container_util.py:1541: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:491: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:492: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:2368: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3343: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3347: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3348: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3351: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3352: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3356: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3358: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3361: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/type_blocks.py:3366: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:228: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:231: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:332: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:419: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:458: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:459: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:482: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:1031: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:1088: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index.py:1899: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index_hierarchy.py:492: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index_hierarchy.py:494: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index_hierarchy.py:567: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index_hierarchy.py:2177: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/index_auto.py:85: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/archive_npy.py:232: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/series.py:634: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/series.py:636: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/series.py:639: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/series.py:642: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/series.py:645: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/frame.py:1304: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/frame.py:1441: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/frame.py:3491: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/frame.py:3494: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/frame.py:3497: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/frame.py:3499: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/bus.py:524: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/bus.py:526: error: Unused "type: ignore" comment [unused-ignore]+ static_frame/core/bus.py:528: error: Unused "type: ignore" comment [unused-ignore]

@hauntsaninja

Copy link
Copy Markdown
CollaboratorAuthor

The black case is covered by a test from #20603


def bar(y: Any):
if y.__class__ == int:
reveal_type(y) # N: Revealed type is "Any"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I think this Any will actually get fixed by #20643

@JukkaLJukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm glad to see so many type ignores fixed! Thanks!

@JukkaL
JukkaL merged commit 1288f20 into python:masterJan 26, 2026
23 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@hauntsaninja@JukkaL