Add exception to descriptor protocol for MethodType().__func__. #3484
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
types.FunctionType
is annotated as a descriptor returningtypes.MethodType
. In general, this is correct: if you access aFunctionType
as an attribute of some instance, you get back aMethodType
.But
MethodType
has an attribute__func__
, which is aFunctionType
. And this attribute does not obey the descriptor protocol; it really does give you aFunctionType
, not aMethodType
.(I think in general
MethodType
, as a type implemented in C, doesn't obey the descriptor protocol: e.g. this is true of its__self__
attribute too, even if the self-object of a method is a descriptor, if you accessmymethod.__self__
you get the object, not the return value of its__get__
method. But__self__
does not currently require special-casing here, because mypy just considers it to be of typeobject
, which isn't a descriptor; mypy doesn't track the type of the actual__self__
of a given method.)This pull request fixes mypy's type inference so it knows that
mymethod.__func__
is aFunctionType
, not aMethodType
.