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
This feels related to #8869, but different enough to warrant a separate issue.
There, the issue was that a bound method of MethodType is incorrectly rejected as a Callable, here, I'm noticing that an unbound class method is rejected as a FunctionType:
To Reproduce
importtypesclassCls:
defmeth(self):
passassertisinstance(Cls.meth, types.FunctionType) # no problemx: types.FunctionType=Cls.meth
Incompatible types in assignment (expression has type"Callable[[Cls], Any]", variable has type"FunctionType") [assignment]
Expected Behavior
I expected an unbound class method to work for an argument expecting FunctionType
Actual Behavior
Incompatible types in assignment
Your Environment
mypy 0.790
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.8.6
Operating system and version: macos 10.15.7
Additional info
(In this case, I didn't want to use x: Callable because I'd like to be able to assert that the standard function object methods will be available)
The text was updated successfully, but these errors were encountered:
Actually, I guess I'm realizing that mypy more generally interprets Callable as having many of the attributes of a typical FunctionType ... though this may not always be the case. For example. The following code will fail at runtime with AttributeError: 'Cls' object has no attribute '__name__', but mypy has no problem with it:
tlambert03
changed the title
Unbound method incorrectly rejected as FunctionType
Unbound method rejected as FunctionType, Callable cast as FunctionType
Jan 21, 2021
Bug Report
This feels related to #8869, but different enough to warrant a separate issue.
There, the issue was that a bound method of
MethodType
is incorrectly rejected as a Callable, here, I'm noticing that an unbound class method is rejected as aFunctionType
:To Reproduce
Expected Behavior
I expected an unbound class method to work for an argument expecting
FunctionType
Actual Behavior
Incompatible types in assignment
Your Environment
mypy.ini
(and other config files): noneAdditional info
(In this case, I didn't want to use
x: Callable
because I'd like to be able to assert that the standard function object methods will be available)The text was updated successfully, but these errors were encountered: