Closed
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.