File tree 1 file changed +16
-1
lines changed
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -121,8 +121,23 @@ class CoroutineType:
121
121
@overload
122
122
def throw (self , typ : type , val : BaseException = ..., tb : 'TracebackType' = ...) -> Any : ...
123
123
124
+ class _StaticFunctionType :
125
+ """Fictional type to correct the type of MethodType.__func__.
126
+
127
+ FunctionType is a descriptor, so mypy follows the descriptor protocol and
128
+ converts MethodType.__func__ back to MethodType (the return type of
129
+ FunctionType.__get__). But this is actually a special case; MethodType is
130
+ implemented in C and its attribute access doesn't go through
131
+ __getattribute__.
132
+
133
+ By wrapping FunctionType in _StaticFunctionType, we get the right result;
134
+ similar to wrapping a function in staticmethod() at runtime to prevent it
135
+ being bound as a method.
136
+ """
137
+ def __get__ (self , obj : Optional [object ], type : Optional [type ]) -> 'FunctionType' : ...
138
+
124
139
class MethodType :
125
- __func__ = ... # type: FunctionType
140
+ __func__ = ... # type: _StaticFunctionType
126
141
__self__ = ... # type: object
127
142
def __call__ (self , * args : Any , ** kwargs : Any ) -> Any : ...
128
143
class BuiltinFunctionType :
You can’t perform that action at this time.
0 commit comments