-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
false positive: "Overloaded function signatures ... overlap with incompatible return types" #11165
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
Comments
The following example may be related. It is something we are trying to get working with respect to pandas stubs supplied by Microsoft with VS Code. Full discussion microsoft/python-type-stubs#87 Goal is to have two parameters
@overload
def myfun(fake: str, i1: Literal[True], cs: Union[int, None] = ...) -> str:
...
@overload
def myfun(fake: str, i1: Literal[False], cs: int) -> str:
...
@overload
def myfun(fake: str, i1: Literal[False] = ..., cs: None = ...) -> int:
...
@overload
def myfun(fake: str, i1: bool = ..., cs: int = ...) -> str:
...
def myfun(fake: str, i1: bool = False, cs: Optional[int] = None) -> Union[str, int]:
print(f"i1 is {i1} cs is {cs} result is ", end="")
if i1:
if cs is not None:
return "TextFileReader"
else:
return "TextFileReader"
else:
if cs is not None:
return "TextFileReader"
else:
return -1
res1: int = myfun("meh")
res2: int = myfun("meh", i1=False)
res3: int = myfun("meh", i1=False, cs=None)
res4: str = myfun("meh", i1=False, cs=23)
res5: str = myfun("meh", i1=True)
res6: str = myfun("meh", i1=True, cs=None)
res7: str = myfun("meh", i1=True, cs=23)
res8: int = myfun("meh", cs=None)
res9: str = myfun("meh", cs=23)
The |
I think what's confusing mypy is the fact that @overload
def myfun(fake: str, *, i1: Literal[True], cs: int | None = ...) -> str:
...
@overload
def myfun(fake: str, *, i1: Literal[False], cs: int) -> str:
...
@overload
def myfun(fake: str, *, i1: Literal[False] = ..., cs: None = ...) -> int:
...
@overload
def myfun(fake: str, *, i1: bool = ..., cs: int) -> str:
...
def myfun(fake: str, i1: bool = False, cs: Optional[int] = None) -> Union[str, int]:
print(f"i1 is {i1} cs is {cs} result is ", end="")
if i1:
if cs is not None:
return "TextFileReader"
else:
return "TextFileReader"
else:
if cs is not None:
return "TextFileReader"
else:
return -1
res1: int = myfun("meh")
res2: int = myfun("meh", i1=False)
res3: int = myfun("meh", i1=False, cs=None)
res4: str = myfun("meh", i1=False, cs=23)
res5: str = myfun("meh", i1=True)
res6: str = myfun("meh", i1=True, cs=None)
res7: str = myfun("meh", i1=True, cs=23)
res8: int = myfun("meh", cs=None)
res9: str = myfun("meh", cs=23) |
|
Possibly related: #6580 |
I think this is another example: |
Bug Report
Code of a certain form causes a false positive error:
To Reproduce
Gist: mypy-play.net
Expected Behavior
There should be no errors.
bool
vs.Literal[True]
)Union[...]
vs.Union[..., T2]
)Actual Behavior
An error is issued:
Additional notes
This example is fairly minimal:
a2
argument from all three declarations causes the problem to disappearSequence[T2]
clause from the returnUnion
of all three declarations causes the problem to disappearYour Environment
mypy.ini
(and other config files): (none)The text was updated successfully, but these errors were encountered: