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

False negative with ParamSpec #13890

Closed
hauntsaninja opened this issue Oct 13, 2022 · 7 comments · Fixed by #13892
Closed

False negative with ParamSpec #13890

hauntsaninja opened this issue Oct 13, 2022 · 7 comments · Fixed by #13892
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@hauntsaninja
Copy link
Collaborator

On mypy master, this does not have any errors:

from typing import Callable, ParamSpec

P = ParamSpec('P')

def twice(f: Callable[P, int], *args: P.args) -> int:
  return f(*args) + f(*args)

With 0.982 you get main.py:5: error: Name "P.args" is not defined. Not the best error message, but at least you get an error for invalid use.

This bisects to https://github.com/python/mypy/pull/13472/files cc @sobolevn

@hauntsaninja hauntsaninja added bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate labels Oct 13, 2022
@sobolevn
Copy link
Member

Fixed! Sending a PR.

@nickeldan
Copy link

nickeldan commented Oct 15, 2022

Perhaps I'm missing something but what is the error? Isn't that the correct usage of P.args?

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 15, 2022

Perhaps I'm missing something but what is the error? Isn't that the correct usage of P.args?

It's invalid to use only P.args in a function. You have to use P.args and P.kwargs, or neither. This is specified in PEP 612 (https://peps.python.org/pep-0612/#id1), but isn't currently mentioned in the typing.py docs (maybe it should be).

@nickeldan
Copy link

It's invalid to use only P.args in a function. You have to use P.args and P.kwargs, or neither. This is specified in PEP 612 (https://peps.python.org/pep-0612/#id1), but isn't currently mentioned in the typing.py docs (it probably should be).

Ah, thanks!

@sobolevn
Copy link
Member

@AlexWaygood would you care to create an issue about that?

@AlexWaygood
Copy link
Member

@AlexWaygood would you care to create an issue about that?

About the CPython docs?

@sobolevn
Copy link
Member

Yes, about:

It's invalid to use only P.args in a function. You have to use P.args and P.kwargs, or neither. This is specified in PEP 612 (https://peps.python.org/pep-0612/#id1), but isn't currently mentioned in the typing.py docs (maybe it should be).

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.

4 participants