I have a stack of several commits that improve mypy's narrowing
I will post relevant PRs and notes in this thread
The first PR is:
This is the foundation for everything else and fixes several issues. It's been open for two weeks, so I will probably merge it in another week or so if there aren't comments
In case useful, for now I have several of my queued changes visible together on this branch: hauntsaninja#5
The second PR is pure refactoring (as a follow up to #20492 ):
I also opened a third PR with some more test cases:
Note the first PR does introduce three regressions that I haven't yet solved:
A fourth PR is better narrowing for NotImplemented:
This next one is a useful one! Fifth PR is narrowing for collection containment:
Contributor PRs to follow up on as stack is merged: #20603 (done) #20277 (open) #20538 (done)
Sixth PR improves logic with enum subclasses:
Add this test: #20602 (comment) (done in stack)
Seventh PR:
Eighth PR (exploratory for now, do not review):
Ninth PR is trivial testing related changes:
Tenth PR adds support for narrowing in type(x) is type(y), which seems pretty common in primer:
Thirty second PR improves logic within conditional_types for unions:
Thirty third PR improves narrowing with final type objects:
Thirty fourth improves match statement narrowing against unions:
Thirtyfifth fixes an issue with custom equality:
Thirtysixth is unsound but we see there are some primer hits now:
Thirtyseventh avoids narrowing NewType:
Thirtyeighth for irrefutable sequence patterns:
Fortieth PR is better narrowing for callables with generic return types:
Fortyfirst PR for better match narrowing for type objects:
Fortysecond PR improves narrowing reachability for tuple as patterns:
Fixes more issues than I expected, guess people really like matching tuples
Fortythird PR for match narrowing of unions of type objects:
Fortyfourth PR for match narrowing of irrefutable map patterns:
Time for changelog post: #21006
Update changelog for narrowing changes (python#21006)
Activity
hauntsaninja commented on Jan 11, 2026
The first PR is:
This is the foundation for everything else and fixes several issues. It's been open for two weeks, so I will probably merge it in another week or so if there aren't comments
hauntsaninja commented on Jan 14, 2026
In case useful, for now I have several of my queued changes visible together on this branch: hauntsaninja#5
hauntsaninja commented on Jan 16, 2026
The second PR is pure refactoring (as a follow up to #20492 ):
I also opened a third PR with some more test cases:
hauntsaninja commented on Jan 16, 2026
Note the first PR does introduce three regressions that I haven't yet solved:
hauntsaninja commented on Jan 16, 2026
A fourth PR is better narrowing for NotImplemented:
hauntsaninja commented on Jan 16, 2026
This next one is a useful one! Fifth PR is narrowing for collection containment:
hauntsaninja commented on Jan 16, 2026
Contributor PRs to follow up on as stack is merged: #20603 (done) #20277 (open) #20538 (done)
hauntsaninja commented on Jan 17, 2026
Sixth PR improves logic with enum subclasses:
hauntsaninja commented on Jan 22, 2026
Add this test: #20602 (comment) (done in stack)
hauntsaninja commented on Jan 22, 2026
Seventh PR:
hauntsaninja commented on Jan 22, 2026
Eighth PR (exploratory for now, do not review):
hauntsaninja commented on Jan 22, 2026
Ninth PR is trivial testing related changes:
hauntsaninja commented on Jan 23, 2026
Tenth PR adds support for narrowing in type(x) is type(y), which seems pretty common in primer:
22 remaining items
hauntsaninja commented on Feb 3, 2026
Thirty second PR improves logic within conditional_types for unions:
hauntsaninja commented on Feb 5, 2026
Thirty third PR improves narrowing with final type objects:
hauntsaninja commented on Feb 5, 2026
Thirty fourth improves match statement narrowing against unions:
hauntsaninja commented on Feb 6, 2026
Thirtyfifth fixes an issue with custom equality:
hauntsaninja commented on Feb 6, 2026
Thirtysixth is unsound but we see there are some primer hits now:
hauntsaninja commented on Feb 8, 2026
Thirtyseventh avoids narrowing NewType:
hauntsaninja commented on Feb 11, 2026
Thirtyeighth for irrefutable sequence patterns:
hauntsaninja commented on Feb 23, 2026
Fortieth PR is better narrowing for callables with generic return types:
hauntsaninja commented on Feb 23, 2026
Fortyfirst PR for better match narrowing for type objects:
hauntsaninja commented on Feb 25, 2026
Fortysecond PR improves narrowing reachability for tuple as patterns:
Fixes more issues than I expected, guess people really like matching tuples
hauntsaninja commented on Feb 26, 2026
Fortythird PR for match narrowing of unions of type objects:
hauntsaninja commented on Feb 26, 2026
Fortyfourth PR for match narrowing of irrefutable map patterns:
hauntsaninja commented on Mar 11, 2026
Time for changelog post: #21006
Update changelog for narrowing changes (python#21006)