-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-callsFunction calls, *args, **kwargs, defaultsFunction calls, *args, **kwargs, defaultstopic-protocols
Description
When I run mypy on the following code:
from types import MethodType
from typing import Callable
def describe(func: Callable[[], None]) -> str:
if isinstance(func, MethodType):
return 'bound method'
else:
return 'other callable'
class C:
def m(self) -> None:
pass
print(describe(C().m))It outputs:
$ mypy --warn-unreachable methodtype.py
methodtype.py:6: error: Statement is unreachable
This statement is return 'bound method'.
If you run the test case, you will see "bound method" being printed, so the code is reachable in practice.
For some reason the problem disappears if the annotation func: Callable[[], None] is changed to just func: Callable.
I'm using mypy 0.770 on Python 3.8.2, with the --warn-unreachable option.
russelldavis, eIGato, ravwojdyla and posita
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-1-normaltopic-callsFunction calls, *args, **kwargs, defaultsFunction calls, *args, **kwargs, defaultstopic-protocols