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

PEP-612 Concatenate not recognized properly #11833

Closed
wrobell opened this issue Dec 23, 2021 · 2 comments · Fixed by #11847
Closed

PEP-612 Concatenate not recognized properly #11833

wrobell opened this issue Dec 23, 2021 · 2 comments · Fixed by #11847
Labels
feature topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@wrobell
Copy link

wrobell commented Dec 23, 2021

Please consider example from PEP-612

from typing import Concatenate, Callable, TypeVar, ParamSpec

R = TypeVar('R')
P = ParamSpec('P')

class Request:
    pass

def with_request(f: Callable[Concatenate[Request, P], R]) -> Callable[P, R]:
  def inner(*args: P.args, **kwargs: P.kwargs) -> R:
    return f(Request(), *args, **kwargs)
  return inner

then

$ mypy t6.py
t6.py:9: error: The first argument to Callable must be a list of types or "..."
Found 1 error in 1 file (checked 1 source file)

I would expect Concatenate to be accepted as the first argument of Callable.

Mypy 0.930, Python 3.10.1

@wrobell wrobell added the bug mypy got something wrong label Dec 23, 2021
@wrobell
Copy link
Author

wrobell commented Dec 23, 2021

Without recognizing Concatenate, one has to use args as a tuple (i.e. access first argument with args[0]), which is disallowed by PEP-612 and Mypy (see also #11826).

@srittau
Copy link
Contributor

srittau commented Dec 23, 2021

Part of #8645

@97littleleaf11 97littleleaf11 added the topic-paramspec PEP 612, ParamSpec, Concatenate label Feb 20, 2022
@AlexWaygood AlexWaygood added feature and removed bug mypy got something wrong labels Mar 30, 2022
JukkaL pushed a commit that referenced this issue Apr 7, 2022
This PR adds a new Parameters proper type to represent ParamSpec parameters 
(more about this in the PR), along with supporting the Concatenate operator.

Closes #11833
Closes #12276
Closes #12257
Refs #8645
External ref python/typeshed#4827

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@regisb regisb mentioned this issue Apr 14, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants