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
spec: expand Never/NoReturn section with precise subtyping rules (#1458)
The previous spec described Never in four lines without defining any of
its subtyping behaviour. Type checkers converge on a consistent set of
rules, but none were written down. This commit codifies them.
Spec changes (docs/spec/special-types.rst):
- Never is a subtype of every fully static type (bottom type property)
- No type other than Never (and Any) is a subtype of Never
- Never | T collapses to T for any type T
- Never as a type argument: covariant containers accept it,
invariant containers do not
- type[Never] represents an uninhabitable class object
- Clarify that NoReturn may appear in non-return positions
Conformance test changes (conformance/tests/specialtypes_never.py):
- Add func11: Never | int collapses to int
- Add func12: object is not assignable to Never (E)
- Add func13: raise in Never-returning function is OK
- Add func14: type[Never] is a valid annotation
- Add func15: list[Never] return is valid
- Add func16: list[Never] is not assignable to list[int] (E)
Result TOMLs updated for mypy, pyright, pyrefly, zuban (Pass).
ty marked Partial: does not flag func12 and func16 errors.
Closes#1458
0 commit comments