Skip to content

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

Description

@ikonst

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

Activity

  1. erictraut commented on Feb 6, 2023

    @erictraut

    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.)

  2. ikonst commented on Feb 6, 2023

    @ikonst
    ContributorAuthor

    @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.

  3. changed the title [-]False-positive for ParamSpec.args as tuple[/-] [+]False-negative: ParamSpec.args annotating non-*args[/+] on Feb 6, 2023
  4. added a commit that references this issue on Jan 2, 2025
    025642b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions