You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypesimportMethodTypem: MethodTypeifisinstance(m.__func__, MethodType): # error: Subclass of "FunctionType" and "MethodType" cannot exist: "FunctionType" is final [unreachable] \# error: Subclass of "FunctionType" and "MethodType" cannot exist: "MethodType" is final [unreachable]m=m.__func__# error: Statement is unreachable [unreachable]
As I implemented the Mypy change, I double-checked that I did not break something. But it seems the definition of MethodType in typeshed is inconsistent. Its __init__ method accepts Callable (#1499), but its __func__ attribute returns FunctionType (#1383). As MethodType can accept and return other methods at runtime, it seems right to define the return type as Callable, too.
The text was updated successfully, but these errors were encountered:
Since version 1.8, Mypy does not intersect types in isinstance checks if at least one is final. In my code base, this leads to unexpected unreachable warnings. I could narrow them down to:
As I implemented the Mypy change, I double-checked that I did not break something. But it seems the definition of
MethodType
in typeshed is inconsistent. Its__init__
method acceptsCallable
(#1499), but its__func__
attribute returnsFunctionType
(#1383). AsMethodType
can accept and return other methods at runtime, it seems right to define the return type asCallable
, too.The text was updated successfully, but these errors were encountered: