A NoReturn
type is needed · Issue #165 · python/typing (original) (raw)
In order to perform branch analysis, it is necessary to know which calls will never return normally. Examples are sys.exit
(which always returns via exception) and os.exit
(which never returns).
NoReturn
should drop out of Union
and dominate Intersection
.
To manually mark a branch as dead, use cast(NoReturn, expression)
in an expression context, or raise
in statement context.
This can also be used as the return type of __init__
or __new__
or the metaclass's __call__
to indicate types that can't be normally instantiated.