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

Support ParamSpec mapping with functools.partial #17355

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sterliakov
Copy link
Contributor

@sterliakov sterliakov commented Jun 10, 2024

Follow-up for #17323, resolving a false positive discovered there.

This enables use of functools.partial to bind some *args or **kwargs on a callable typed with ParamSpec.

This comment has been minimized.

Copy link
Contributor

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

optuna (https://github.com/optuna/optuna)
+ optuna/_convert_positional_args.py:83: error: Too few arguments  [call-arg]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ tests/test_series.py:3022: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[Series[Any], int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], Series[Any]]", "str", "list[float]", "str", "tuple[int, int]"  [call-overload]
+ tests/test_series.py:3022: note: Possible overload variants:
+ tests/test_series.py:3022: note:     def [P`33582, T] pipe(self, func: Callable[[Series[int], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_series.py:3022: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_series.py:3024: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_series.py:3036: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[Series[Any], int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], Series[Any]]", "int", "list[float]", "int", "tuple[int, int]"  [call-overload]
+ tests/test_series.py:3036: note: Possible overload variants:
+ tests/test_series.py:3036: note:     def [P`33607, T] pipe(self, func: Callable[[Series[int], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_series.py:3036: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_series.py:3040: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_series.py:3050: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_series.py:3050: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[Series[Any], int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], Series[Any]]", "int", "list[float]", "str", "tuple[int, int]"  [call-overload]
+ tests/test_series.py:3050: note: Error code "call-overload" not covered by "type: ignore" comment
+ tests/test_series.py:3050: note: Possible overload variants:
+ tests/test_series.py:3050: note:     def [P`33632, T] pipe(self, func: Callable[[Series[int], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_series.py:3050: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_series.py:3057: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_series.py:3057: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[Series[Any], int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], Series[Any]]", "int", "list[float]", "int", "tuple[int, int]"  [call-overload]
+ tests/test_series.py:3057: note: Error code "call-overload" not covered by "type: ignore" comment
+ tests/test_series.py:3057: note: Possible overload variants:
+ tests/test_series.py:3057: note:     def [P`33643, T] pipe(self, func: Callable[[Series[int], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_series.py:3057: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_series.py:3061: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_series.py:3064: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_series.py:3064: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[Series[Any], int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], Series[Any]]", "int", "list[float]", "int", "tuple[int, int]"  [call-overload]
+ tests/test_series.py:3064: note: Error code "call-overload" not covered by "type: ignore" comment
+ tests/test_series.py:3064: note: Possible overload variants:
+ tests/test_series.py:3064: note:     def [P`33654, T] pipe(self, func: Callable[[Series[int], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_series.py:3064: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_series.py:3068: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_resampler.py:202: error: No overload variant of "pipe" of "BaseGroupBy" matches argument types "Callable[[DatetimeIndexResampler[DataFrame], int, list[float], str, NamedArg(tuple[int], 'kw')], DataFrame]", "str", "list[float]", "str", "tuple[int]"  [call-overload]
+ tests/test_resampler.py:202: note: Possible overload variants:
+ tests/test_resampler.py:202: note:     def [P`35986, T] pipe(self, func: Callable[[DatetimeIndexResampler[DataFrame], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_resampler.py:202: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_resampler.py:204: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_resampler.py:216: error: No overload variant of "pipe" of "BaseGroupBy" matches argument types "Callable[[DatetimeIndexResampler[DataFrame], int, list[float], str, NamedArg(tuple[int], 'kw')], DataFrame]", "int", "list[float]", "int", "tuple[int]"  [call-overload]
+ tests/test_resampler.py:216: note: Possible overload variants:
+ tests/test_resampler.py:216: note:     def [P`36015, T] pipe(self, func: Callable[[DatetimeIndexResampler[DataFrame], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_resampler.py:216: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_resampler.py:220: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_resampler.py:230: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_resampler.py:230: error: No overload variant of "pipe" of "BaseGroupBy" matches argument types "Callable[[DatetimeIndexResampler[DataFrame], int, list[float], str, NamedArg(tuple[int], 'kw')], DataFrame]", "int", "list[float]", "str", "tuple[int]"  [call-overload]
+ tests/test_resampler.py:230: note: Error code "call-overload" not covered by "type: ignore" comment
+ tests/test_resampler.py:230: note: Possible overload variants:
+ tests/test_resampler.py:230: note:     def [P`36044, T] pipe(self, func: Callable[[DatetimeIndexResampler[DataFrame], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_resampler.py:230: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_resampler.py:237: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_resampler.py:237: error: No overload variant of "pipe" of "BaseGroupBy" matches argument types "Callable[[DatetimeIndexResampler[DataFrame], int, list[float], str, NamedArg(tuple[int], 'kw')], DataFrame]", "int", "list[float]", "int", "tuple[int]"  [call-overload]
+ tests/test_resampler.py:237: note: Error code "call-overload" not covered by "type: ignore" comment
+ tests/test_resampler.py:237: note: Possible overload variants:
+ tests/test_resampler.py:237: note:     def [P`36057, T] pipe(self, func: Callable[[DatetimeIndexResampler[DataFrame], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_resampler.py:237: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_resampler.py:241: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_resampler.py:244: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_resampler.py:244: error: No overload variant of "pipe" of "BaseGroupBy" matches argument types "Callable[[DatetimeIndexResampler[DataFrame], int, list[float], str, NamedArg(tuple[int], 'kw')], DataFrame]", "int", "list[float]", "int", "tuple[int]"  [call-overload]
+ tests/test_resampler.py:244: note: Error code "call-overload" not covered by "type: ignore" comment
+ tests/test_resampler.py:244: note: Possible overload variants:
+ tests/test_resampler.py:244: note:     def [P`36070, T] pipe(self, func: Callable[[DatetimeIndexResampler[DataFrame], **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_resampler.py:244: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_resampler.py:248: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_frame.py:1611: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[DataFrame, int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], DataFrame]", "str", "list[float]", "str", "tuple[int, int]"  [call-overload]
+ tests/test_frame.py:1611: note: Possible overload variants:
+ tests/test_frame.py:1611: note:     def [P`47493, T] pipe(self, func: Callable[[DataFrame, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_frame.py:1611: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_frame.py:1613: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_frame.py:1625: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[DataFrame, int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], DataFrame]", "int", "list[float]", "int", "tuple[int, int]"  [call-overload]
+ tests/test_frame.py:1625: note: Possible overload variants:
+ tests/test_frame.py:1625: note:     def [P`47518, T] pipe(self, func: Callable[[DataFrame, **P], T], *args: P.args, **kwargs: P.kwargs) -> T
+ tests/test_frame.py:1625: note:     def [T] pipe(self, func: tuple[Callable[..., T], str], *args: Any, **kwargs: Any) -> T
+ tests/test_frame.py:1629: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_frame.py:1639: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_frame.py:1639: error: No overload variant of "pipe" of "NDFrame" matches argument types "Callable[[DataFrame, int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], DataFrame]", "int", "list[float]", "str", "tuple[int, int]"  [call-overload]
+ tests/test_frame.py:1639: note: Error code "call-overload" not covered by "type: ignore" comment
+ tests/test_frame.py:1639: note: Possible overload variants:

... (truncated 16 lines) ...

pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/gdblib/events.py: note: In function "connect":
+ pwndbg/gdblib/events.py:124: error: Too few arguments  [call-arg]

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.

None yet

1 participant