Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalise attribute __func__ of class MethodType from FunctionType to Callable #11201

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions stdlib/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -418,26 +418,14 @@ class CoroutineType(Coroutine[_YieldT_co, _SendT_contra, _ReturnT_co]):
@overload
def throw(self, __typ: BaseException, __val: None = None, __tb: TracebackType | None = ...) -> _YieldT_co: ...

class _StaticFunctionType:
# Fictional type to correct the type of MethodType.__func__.
# FunctionType is a descriptor, so mypy follows the descriptor protocol and
# converts MethodType.__func__ back to MethodType (the return type of
# FunctionType.__get__). But this is actually a special case; MethodType is
# implemented in C and its attribute access doesn't go through
# __getattribute__.
# By wrapping FunctionType in _StaticFunctionType, we get the right result;
# similar to wrapping a function in staticmethod() at runtime to prevent it
# being bound as a method.
def __get__(self, obj: object, type: type | None) -> FunctionType: ...

@final
class MethodType:
@property
def __closure__(self) -> tuple[_Cell, ...] | None: ... # inherited from the added function
@property
def __defaults__(self) -> tuple[Any, ...] | None: ... # inherited from the added function
@property
def __func__(self) -> _StaticFunctionType: ...
def __func__(self) -> Callable[..., Any]: ...
@property
def __self__(self) -> object: ...
@property
Expand Down