The following example produces an error in mypy --strict mode:
import typing
TypeSpec = typing.Any
def is_union(spec: TypeSpec) -> bool:
return typing.get_origin(spec) is typing.Union
(it does work without the type alias).
This gives:
$ mypy --strict t.py
t.py:6: error: Non-overlapping identity check (left operand type: "type", right operand type: "<typing special form>") [comparison-overlap]
It looks like get_origin() is declared to return type, but it can actually return some other things, notably Union and Literal.
mypy versions 1.4.1.
The following example produces an error in mypy --strict mode:
(it does work without the type alias).
This gives:
It looks like get_origin() is declared to return
type, but it can actually return some other things, notablyUnionandLiteral.mypy versions 1.4.1.