You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Narrowing types does not consider the @final decorator #20590
This is related to #20041. Basically when trying to narrow a type object, using issubclass makes sense instead of is since the narrowing considers that subclasses can be used as replacement. For me however, it makes sense that issubclass be the same as is when the type is marked @final since the subclasses for the type cannot exist.
I expect the types to be narrowed down when using is if the type is marked @final.
Actual Behavior
main.py:17: note: Revealed type is "type[__main__.Types.A]"
main.py:20: note: Revealed type is "type[__main__.Types.B]"
main.py:22: note: Revealed type is "type[__main__.Types.A] | type[__main__.Types.B]"
main.py:23: error: Argument 1 to "assert_never" has incompatible type "type[A] | type[B]"; expected "Never" [arg-type]
The type does not narrow, see main.py:22
Your Environment
Mypy version used: mypy 1.19.1 (compiled: yes)
Mypy command-line flags:
Mypy configuration options from mypy.ini (and other config files): N/A
Activity
[-]Narrowing does not consider the @final decorator[/-][+]Narrowing types does not consider the @final decorator[/+]Fix type narrowing for @Final classes with identity checks
shiva-sai-824 commentedon Jan 21, 2026
@baluyotraf Can you please review my PR?
Fix type narrowing for @Final classes with identity checks
Narrowing for final type objects (python#20661)