Skip to content

[operator] Replace or explain Any#15597

Draft
srittau wants to merge 5 commits intopython:mainfrom
srittau:operator-any
Draft

[operator] Replace or explain Any#15597
srittau wants to merge 5 commits intopython:mainfrom
srittau:operator-any

Conversation

@srittau
Copy link
Copy Markdown
Collaborator

@srittau srittau commented Apr 2, 2026

No description provided.

@github-actions

This comment has been minimized.

class methodcaller:
def __new__(cls, name: str, /, *args: Any, **kwargs: Any) -> Self: ...
def __call__(self, obj: Any) -> Any: ...
class methodcaller(Generic[_P, _R]):
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Making this generic, makes it possible to use better methodcallers in annotations, even if type checking is not perfect:

m: methodcaller[[int], str] = methodcaller("foo")  # error (missing argument)

I'll add some tests.

m1 = methodcaller("foo")
assert_type(m1, methodcaller[[], Any])
m2 = methodcaller("foo", 42, bar="")
# assert_type(m2, methodcaller[[int, Arg(str, "bar")], Any])
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is there a way to specialize a ParamSpec's kwargs in older Python versions?

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
Copy link
Copy Markdown
Collaborator Author

srittau commented Apr 2, 2026

I'm not sure why pyright has problems here. microsoft/pyright#11358

@srittau srittau marked this pull request as draft April 2, 2026 09:48
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.

1 participant