Conditional expression in "with" statement inferred as 'object', lacking __enter__ and __exit__ #5512
Labels
bug
mypy got something wrong
false-positive
mypy gave an error on correct code
priority-1-normal
topic-join-v-union
Using join vs. using unions
topic-ternary-expression
a if b else c
Mypy infers the type of the conditional expression as
object
rather thanUnion[IO,TemporaryDirectory]
Explicitly typing the result of the conditional expression makes the error messages go away:
I observe this in both mypy versions I tried: 0.600 and 0.620
These past issues and pull requests look relevant:
#3487 Type of conditional expression is join instead of union
#5041 Fix type of conditional statement to Union and not Join.
#5095 Don't always infer unions for conditional expressions
The text was updated successfully, but these errors were encountered: