Suppose I have:
x: type = Optional[str] # <--- type error
This results in the type error:
Expression of type "UnionType" is incompatible with declared type "type"
"UnionType" is incompatible with "type"
I do not want to type annotate x
with typing.UnionType
, becuase in general it could be any annotation. For example:
x: ? = NamedTuple
x: ? = MyClass
x: ? = str
x: ? = Any
Whatever I put down for ?
should work for a broad class of type annotations. Do I have any good options beyond Any
?
1