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: ParamSpec.args annotating non-*args #14622

Open
ikonst opened this issue Feb 6, 2023 · 2 comments
Open

False-negative: ParamSpec.args annotating non-*args #14622

ikonst opened this issue Feb 6, 2023 · 2 comments
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@ikonst
Copy link
Contributor

ikonst commented Feb 6, 2023

Per the docs, "P.args ... should only be used to annotate *args":

from typing import ParamSpec

P = ParamSpec('P')


def f(args: P.args) -> None:
    g(*args)


def g(a: str) -> None:
    print(type(a))
    
    

f(42)

Gist:
https://mypy-play.net/?mypy=latest&python=3.11&gist=28f03ed1b30e9707edfd080095b6a868

@ikonst ikonst added the bug mypy got something wrong label Feb 6, 2023
@erictraut
Copy link

The code above (in particular, the signature for function f) isn't legal. A P.args annotation can be used only within a context where P is bound to a scope (a generic function or class), only with a *args parameter, and only when paired with a corresponding **kwargs: P.kwargs parameter. See PEP 612 for details.

Mypy should flag the illegal use of P.args as an error. (That makes this a false negative, not a false positive.)

@ikonst
Copy link
Contributor Author

ikonst commented Feb 6, 2023

@erictraut, thanks for jumping in so quickly!

I've read this in the docs

P.args represents the tuple of positional parameters in a given call

and failed to read the rest of it :)

[...] and should only be used to annotate *args

Indeed, then it shall be a false negative.

@ikonst ikonst changed the title False-positive for ParamSpec.args as tuple False-negative: ParamSpec.args annotating non-*args Feb 6, 2023
@AlexWaygood AlexWaygood added the topic-paramspec PEP 612, ParamSpec, Concatenate label Feb 6, 2023
magwas added a commit to kode-konveyor/cdd-python that referenced this issue Mar 1, 2023
magwas added a commit to kode-konveyor/cdd-python that referenced this issue Mar 1, 2023
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

No branches or pull requests

3 participants