Skip to content

Conversation

@AlexWaygood
Copy link
Member

Description

Fixes#12930.

Currently, mypy erroneously emits two errors on this snippet:

fromtyping_extensionsimportParamSpecfromtypingimportCallable, TypeVar, Iterator, Iterable, TupleP=ParamSpec("P") T=TypeVar("T") defenumerate(x: Iterable[T]) ->Iterator[Tuple[int, T]]: ... deffoo(func: Callable[P, T]) ->Callable[P, T]: def_inner(*args: P.args, **kwargs: P.kwargs) ->T: y=enumerate(args) # E: Need type annotation for "y" # E: Argument 1 to "enumerate" has incompatible type "P.args"; expected "Iterable[<nothing>]"returnfunc(*args, **kwargs) return_inner

This is because of a bug in constraints.py: ParamSpecArgs and ParamSpecKwargs have upper bounds following #12668 (tuple[object, ...] and dict[str, object] respectively), but the constraints solver isn't currently aware of that fact. This PR fixes that bug.

Test Plan

I added a test to one of the existing test cases.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstraJelleZijlstra merged commit 8153e47 into python:masterJun 4, 2022
@AlexWaygoodAlexWaygood deleted the enumerate branch June 4, 2022 15:28
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ParamspecArgs cannot be used with enumerate

2 participants

@AlexWaygood@JelleZijlstra