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 6 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

This comment has been minimized.

@A5rocks A5rocks requested a review from ilevkivskyi February 17, 2025 15:30
Copy link
Contributor

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

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]

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]

django-stubs (https://github.com/typeddjango/django-stubs): 1.40x faster (57.8s -> 41.2s in a single noisy sample)
+ django-stubs/test/client.pyi:252: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:262: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:273: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:283: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:294: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:305: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:316: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:327: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:353: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:363: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:374: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:384: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:395: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:406: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:417: error: Unused "type: ignore" comment  [unused-ignore]
+ django-stubs/test/client.pyi:428: 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]

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]

trio (https://github.com/python-trio/trio)
- src/trio/_core/_run.py:2743: error: Argument 1 to "run" of "Context" has incompatible type "Callable[[Any], object] | None"; expected "Callable[[Outcome[Any] | BaseException | None], object]"  [arg-type]
+ src/trio/_core/_run.py:2743: error: Argument 1 to "run" of "Context" has incompatible type "Callable[[Any], object] | None"; expected "Callable[[Any], object]"  [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
2 participants