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

a wrapper has ParamSpec + more args = error #16402

Closed
hydrargyrum opened this issue Nov 3, 2023 · 2 comments
Closed

a wrapper has ParamSpec + more args = error #16402

hydrargyrum opened this issue Nov 3, 2023 · 2 comments
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@hydrargyrum
Copy link

hydrargyrum commented Nov 3, 2023

Bug Report

The following snippet generates a main.py:7: error: ParamSpec must have "*args" typed as "P.args" and "**kwargs" typed as "P.kwargs" [valid-type] error, though the suggestion is followed

It's supposed to be a wrapper that schedules a call for later (typically for dispatching to a job queue)

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=e0bea0d9c56d64d145b87c80bd003c77

from typing import Callable, ParamSpec, TypeVar

P = ParamSpec("P")
R = TypeVar("R")


def schedule(
    func: Callable[P, R],
    useless: bool = True,
    *args: P.args,
    timeout: int = 0,
    **kwargs: P.kwargs
) -> None:
    func(*args, **kwargs)

Expected Behavior

There should be no error:

  • the wrapper takes a callback, its arguments, plus some additional ones
  • the wrapper calls the callback with the appropriate args (though it should schedule the call for later, but that's another story)

Actual Behavior

main.py:7: error: ParamSpec must have "*args" typed as "P.args" and "**kwargs" typed as "P.kwargs" [valid-type]

Your Environment

  • Mypy version used: latest, see playground
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files): from playground
  • Python version used: 3.11
@hydrargyrum hydrargyrum added the bug mypy got something wrong label Nov 3, 2023
@AlexWaygood AlexWaygood added false-positive mypy gave an error on correct code topic-paramspec PEP 612, ParamSpec, Concatenate labels Nov 3, 2023
@erictraut
Copy link

This is related to #13966.

PEP 612, which introduced ParamSpec to the type system, specifies that a *args: P.args and **kwargs: P.kwargs parameter must be located next to each other. You cannot insert additional keyword arguments between them, as you have done in your example. Mypy's error message here could be improved.

@AlexWaygood AlexWaygood removed the false-positive mypy gave an error on correct code label Nov 3, 2023
@ilevkivskyi
Copy link
Member

Duplicate of #13966

@ilevkivskyi ilevkivskyi marked this as a duplicate of #13966 Nov 13, 2023
@ilevkivskyi ilevkivskyi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 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

4 participants