Uh oh!
There was an error while loading. Please reload this page.
Fix type inference in pattern matching by positional argument - #13618
Conversation
This comment has been minimized.
This comment has been minimized.
sobolevn
commented
Sep 7, 2022
I am quite surprised! |
@sobolevn a good surprise indeed! Tests look comprehensive enough. I wonder, does it also run correctly with inheritance? (Note the extra classBase(Generic[T]):
...
@dataclass# problem also occurs with non-dataclass equivalentclassA(Base[T]):
x: Ta: Base[str] =A("foo")
reveal_type(a) # Base[str] (correct)matcha:
caseA(b):
reveal_type(b) # Any (incorrect! Should be builtins.str)It might be a good addition to the tests, because inheritance here breaks |
sobolevn
commented
Sep 7, 2022
I will add a test case for subclasses and dataclasses. Thanks! |
sobolevn
commented
Sep 7, 2022
Ok, this indeed does not work for Let's open a new issue for it. Can you, @ariebovenberg? 🙂 |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
sobolevn
commented
Sep 8, 2022
@thomkeh hi, can you please share any context on your commit? Is there something wrong? |
tmke8
commented
Sep 8, 2022
Oh sorry, I clicked the "revert" button accidentally! I didn't know this was possible. Everything is fine as far as I know. |
Oh, this was very interesting.
During the debug sessions I learned a lot about how pattern matching and its analysis do work.
But, the problem was that
expand_typedid not preserve.last_known_valuefor some reason.I used
.copy_modifiedto preserve everything we know aboutInstance.However, I expect that some tests might fail now. This code even has something similar in
TODOsome lines above:mypy/mypy/expandtype.py
Lines 144 to 148 in 88aed94
Let's see what will happen.
Closes#13612