-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mypy emits two conflicting results for reveal_type #10739
Comments
I think I'm experiencing the same bug, and the revealed types have no overlap: import re
from typing import Union, AnyStr, List
def expect(pattern: Union[re.Pattern[AnyStr], AnyStr, List[AnyStr]]) -> None:
if isinstance(pattern, str):
return
if isinstance(pattern, re.Pattern) and isinstance(pattern.pattern, str):
return
reveal_type(pattern)
|
I did some initial investigation into where the error is and determined that the initial isinstance check is filtering out
I wrote a non-passing test for
When looking at the output, note that x is typed as
|
I made a PR to fix it! yay :) I don't fully understand |
Also, maybe it should be a breaking change on some things and should be I should think about other edge cases as well. |
Bug Report
My colleague @ahuhn and I encountered a situation where mypy emits two different outputs for one
reveal_type
call:Running mypy emits two lines for the
reveal_type
call, one correct and the other incorrect. In the incorrect reveal statement, the type narrowing at the top of the function is lost:Expected Behavior
Expected only one piece of output for one reveal_type, and for that output to maintain the type narrowing from the top of the function.
Your Environment
We encountered this on mypy 0.812, but it also repros on latest master (currently 416f57b) using python 3.8.6.
A variation of interest: if you add a line of code after the
reveal_type
, then the second reveal_type output broadens to includeAny
:mypy:
(In this example, it's trivial to get around the problem by removing the redundant
isinstance(int)
check, but in our actual code, it wasn't so straightforward.)The text was updated successfully, but these errors were encountered: