Open eltoder opened 1 year ago
For your second question, the answer is "yes int | Any
provides more information than Any
alone, and this can be valuable". For example, if you attempt to invoke a method on this value and that method isn't valid for an int
, mypy can tell you about the potential bug. If the int
subtype of the union is dropped, this bug will go unreported.
d.foo(d3)[0].capitalize()
@erictraut ah, good point. If operations on unions are required to be valid for every component of the union, adding alternatives to Any
is actually making the type more precise.
Feature
In the following example (https://mypy-play.net/?mypy=latest&python=3.11&gist=3119048d3a61ecdda21806b02a0bd08c)
the types are revealed as
D[str, Any]
since both overloads returnD[str, ...]
.Union[int, Any]
instead of justAny
? This is probably a general question, but I couldn't find any issues about it. Is there any context in whichUnion[int, Any]
provides any extra information?