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

Recursive use of ParamSpec #13191

Closed
ikonst opened this issue Jul 19, 2022 · 0 comments · Fixed by #15896
Closed

Recursive use of ParamSpec #13191

ikonst opened this issue Jul 19, 2022 · 0 comments · Fixed by #15896
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@ikonst
Copy link
Contributor

ikonst commented Jul 19, 2022

Bug Report

Passing ParamSpec'd function (e.g. named spawn) to itself results in an error:

Argument 1 to "spawn" has incompatible type "Callable[[Arg(Callable[P, T], 'f'), **P], str]";
                                   expected "Callable[[Arg(Callable[P, T], 'f'), **P], str]"

^ indentation added to highlight that the 'actual' and 'expected' types are the same (at least in their rendered form)

My motivation was to type-annotate Greenlet.spawn of the gevent library.

To Reproduce

Gist URL: https://gist.github.com/05a7c5bb1a380684d82210e5589fb048
Playground URL: https://mypy-play.net/?mypy=latest&python=3.10&gist=05a7c5bb1a380684d82210e5589fb048

Your Environment

  • Mypy version used: 0.961
  • Python version used: 3.10
@ikonst ikonst added the bug mypy got something wrong label Jul 19, 2022
@AlexWaygood AlexWaygood added the topic-paramspec PEP 612, ParamSpec, Concatenate label Jul 20, 2022
ilevkivskyi added a commit that referenced this issue Aug 25, 2023
Fixes #12278
Fixes #13191 (more tricky nested
use cases with optional/keyword args still don't work, but they are
quite tricky to fix and may selectively fixed later)

This unfortunately requires some special-casing, here is its summary:
* If actual argument for `Callable[P, T]` is non-generic and non-lambda,
do not put it into inference second pass.
* If we are able to infer constraints for `P` without using arguments
mapped to `*args: P.args` etc., do not add the constraint for `P` vs
those arguments (this applies to both top-level callable constraints,
and for nested callable constraints against callables that are known to
have imprecise argument kinds).

(Btw TODO I added is not related to this PR, I just noticed something
obviously wrong)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants