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

Merge two different applicable argument types when synthesizing corresponding argument #18627

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

A5rocks
Copy link
Collaborator

@A5rocks A5rocks commented Feb 7, 2025

Fixes #18596.
Fixes #16626.

This comment has been minimized.

@A5rocks
Copy link
Collaborator Author

A5rocks commented Feb 9, 2025

Minimizing the prefect change, I find that this PR breaks this:

from typing import Any, Callable, ParamSpec

P = ParamSpec("P")

def into(f: Callable[P, None], *args: P.args, **kwargs: P.kwargs) -> None:
    return None

class C:
    def f(self, y: bool = False, *, x: int = 42) -> None:
        return None

ex: C | Any = C()

into(ex.f, x=-1)  # E: Argument 1 to "into" has incompatible type "Callable[[bool, DefaultNamedArg(int, 'x')], None] | Any"; expected "Callable[[int], None]"

I assume that paramspec callables are somehow messed up?

The fallout is worse lambda inference, but this is more correct
param_spec_arg_kinds.append(
ARG_POS if actual_kind not in (ARG_STAR, ARG_STAR2) else actual_kind
)
param_spec_arg_kinds.append(arg_kinds[actual])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ilevkivskyi I made this change and the only fallout from the test cases seems to be lambda inference (and error messages. Oh well...). I think that's probably a solvable problem, so I'm curious whether I'm missing some case.

Copy link
Member

Choose a reason for hiding this comment

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

I am not only worried about the test cases, the bigger problem is that this change doesn't make much sense to me (read again the comment you deleted). What you are trying to achieve should be done by handling unions here https://github.com/python/mypy/blob/master/mypy/checkexpr.py#L2281-L2291.

Copy link
Collaborator Author

@A5rocks A5rocks Feb 9, 2025

Choose a reason for hiding this comment

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

Yeah that sounds like a better spot to modify.

Just to confirm vocabulary, formal kind is referring to the kind within the (unknown) parameters we want to eventually accept? If so then I figured that since this is a supertype things will work out compatibility-wise.

I mean anyways it's easier to modify where you linked, so I'll do that and revert this change.

Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm vocabulary, formal kind is referring to the kind within the (unknown) parameters we want to eventually accept?

In general "formal" means appearing in function definition, "actual" means appearing in the function call

def foo(**kwargs: int) -> None: ...  # formal kind is ARG_STAR2
foo(x=42)  # actual kind is ARG_NAMED

but in this context essentially yes.

Copy link
Contributor

github-actions bot commented Feb 9, 2025

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

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/_mixins.py:209: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/arrays/_mixins.py:217: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/indexes/multi.py:1314: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/core/indexes/multi.py:2427: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/plotting/_matplotlib/core.py:1605: error: Unused "type: ignore" comment  [unused-ignore]
+ pandas/plotting/_matplotlib/core.py:1772: error: Unused "type: ignore" comment  [unused-ignore]

xarray (https://github.com/pydata/xarray)
+ xarray/core/variable.py:1605: error: Unused "type: ignore" comment  [unused-ignore]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/core/indexes/multi.pyi:131: error: Unused "type: ignore" comment  [unused-ignore]

django-stubs (https://github.com/typeddjango/django-stubs)
+ django-stubs/test/client.pyi:236: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:246: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:257: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:267: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:278: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:289: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:300: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:311: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:337: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:347: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:358: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:368: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:379: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:390: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:401: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:412: error: Unused "type: ignore" comment  [unused-ignore]

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/api.py:804: error: Overloaded function implementation does not accept all possible arguments of signature 2  [misc]

jax (https://github.com/google/jax)
+ jax/experimental/jax2tf/tests/jax2tf_limitations.py:111: error: Unused "type: ignore" comment  [unused-ignore]

kornia (https://github.com/kornia/kornia)
+ kornia/augmentation/container/augment.py:300: error: Unused "type: ignore" comment  [unused-ignore]
+ kornia/augmentation/container/augment.py:427: error: Unused "type: ignore" comment  [unused-ignore]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants