Skip to content

[types] Make MethodType generic - #15993

Open
srittau wants to merge 16 commits into
python:mainfrom
srittau:generic-method-type
Open

[types] Make MethodType generic#15993
srittau wants to merge 16 commits into
python:mainfrom
srittau:generic-method-type

Conversation

@srittau

@srittau srittau commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@srittau

srittau commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator Author

Will be useful for #15977.

@github-actions

This comment has been minimized.

@srittau
srittau marked this pull request as ready for review July 10, 2026 12:40
@github-actions

This comment has been minimized.

Comment thread stdlib/types.pyi Outdated
def __qualname__(self) -> str: ... # inherited from the added function
def __new__(cls, func: Callable[..., Any], instance: object, /) -> Self: ...
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
def __new__(cls, func: Callable[_P_default, _R_default], instance: object, /) -> Self: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't correct, it doesn't account for the fact that the self argument is bound. We may need to Concatenate a parameter that matches instance in type.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pydantic (https://github.com/pydantic/pydantic)
- pydantic/experimental/arguments_schema.py:41: error: Argument 1 to "_arguments_schema" of "GenerateSchema" has incompatible type "Callable[..., Any]"; expected "FunctionType | MethodType | partial[Any]"  [arg-type]
+ pydantic/experimental/arguments_schema.py:41: error: Argument 1 to "_arguments_schema" of "GenerateSchema" has incompatible type "Callable[..., Any]"; expected "FunctionType | MethodType[[VarArg(Any), KwArg(Any)], Any] | partial[Any]"  [arg-type]
- pydantic/experimental/arguments_schema.py:43: error: Argument 1 to "_arguments_v3_schema" of "GenerateSchema" has incompatible type "Callable[..., Any]"; expected "FunctionType | MethodType | partial[Any]"  [arg-type]
+ pydantic/experimental/arguments_schema.py:43: error: Argument 1 to "_arguments_v3_schema" of "GenerateSchema" has incompatible type "Callable[..., Any]"; expected "FunctionType | MethodType[[VarArg(Any), KwArg(Any)], Any] | partial[Any]"  [arg-type]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants