Open
Description
@erictraut has gathered a long list of problems caused by mypy's behavior of using the "join" operator to unify types in various contexts.
- Incompatible return value type (got "function", expected "Callable[..., Any]") #12053
- Attribute of type
A | B | None
becomesobject
after narrowing checks #12009 - enumerate causes incompatible type mypy error #11934
- a joining of two types becomes
object
not a union #11440 - Unable to remove Optional wrapper when using Mapping[str, str] instead of dict #11618
- Expression has type "function", variable has type "Callable[[], None]" #10740
- Join of types depends on order of types #10442
- Incorrect type reification on optional union attribute in conditional #7884
- mypy infers conditional expression of Dict[str, object] to be object instead of union #7835
- Use Union for tuple fallback? #7616
- Wrong type inference (object instead of List) #6968
- Union types for dict keys are not inferred in union context #6079
- Conditional expression in "with" statement inferred as 'object', lacking __enter__ and __exit__ #5512
- False exception error in raise statement with a ternary conditional operator #5128
- Constrained TypeVar fails to narrow on left hand side of conditional expression #4134
- join is not associative in the presence of unions #3339
I believe that we should change this behavior.
If someone opens a PR to do this, it would be interesting to see what the results look like in mypy-primer and mypy's CI.