55### Better narrowing
66
77Mypy's implementation of narrowing has been substantially reworked. Mypy will now narrow more
8- aggressively, more consistently and more correctly. In particular, you are likely to notice new
9- narrowing behaviour in equality expressions (` == ` ), containment expressions (` in ` ),
8+ aggressively, more consistently, and more correctly. In particular, you are likely to notice new
9+ narrowing behavior in equality expressions (` == ` ), containment expressions (` in ` ),
1010match statements, and additional expressions providing type guards.
1111
1212Note that mypy (and other Python type checkers) do not model the potential for various non-local
@@ -28,14 +28,14 @@ Contributed by Shantanu Jain.
2828- Narrow types based on collection containment (Shantanu, PR [ 20602] ( https://github.com/python/mypy/pull/20602 ) )
2929- Refactor and improve narrowing for type(x) == t checks (Shantanu, PR [ 20634] ( https://github.com/python/mypy/pull/20634 ) )
3030- Narrow for type expr comparisons to type exprs (Shantanu, PR [ 20639] ( https://github.com/python/mypy/pull/20639 ) )
31- - Narrowing for comparisons against x.__ class__ (Shantanu, PR [ 20642] ( https://github.com/python/mypy/pull/20642 ) )
31+ - Narrowing for comparisons against ` x.__class__ ` (Shantanu, PR [ 20642] ( https://github.com/python/mypy/pull/20642 ) )
3232- Better narrowing with custom equality (Shantanu, PR [ 20643] ( https://github.com/python/mypy/pull/20643 ) )
3333- Use a single pass for core narrowing logic, add comments (Shantanu, PR [ 20659] ( https://github.com/python/mypy/pull/20659 ) )
3434- Narrowing for final type objects (Shantanu, PR [ 20661] ( https://github.com/python/mypy/pull/20661 ) )
3535- Avoid narrowing type[ T] (Shantanu, PR [ 20662] ( https://github.com/python/mypy/pull/20662 ) )
3636- Avoid widening to Any for checks like ` type(x) is type(y: Any) ` (Shantanu, PR [ 20663] ( https://github.com/python/mypy/pull/20663 ) )
3737- Preserve some lost narrowing, cleanup (Shantanu, PR [ 20674] ( https://github.com/python/mypy/pull/20674 ) )
38- - Fix narrowing related code for types with overloaded __ new__ (Shantanu, PR [ 20676] ( https://github.com/python/mypy/pull/20676 ) )
38+ - Fix narrowing related code for types with overloaded ` __new__ ` (Shantanu, PR [ 20676] ( https://github.com/python/mypy/pull/20676 ) )
3939- Fix isinstance with unions of tuples (Shantanu, PR [ 20677] ( https://github.com/python/mypy/pull/20677 ) )
4040- Fix regression to chained containment (Shantanu, PR [ 20688] ( https://github.com/python/mypy/pull/20688 ) )
4141- Improve else handling with custom equality (Shantanu, PR [ 20692] ( https://github.com/python/mypy/pull/20692 ) )
0 commit comments