-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Regression: ParamSpecs are converted to '...' when used in returned Callable #5283
Comments
This is an ambiguous part of the typing spec. In a strict reading of PEP 484, both |
…tion that returns a callable with a ParamSpec that does not appear outside of the return type annotation. This addresses #5283.
…tion that returns a callable with a ParamSpec that does not appear outside of the return type annotation. This addresses #5283. (#5284) Co-authored-by: Eric Traut <[email protected]>
This will be fixed in the next release. |
This is addressed in pyright 1.1.314, which I just published. It will also be included in this week's Pylance prerelease build. |
@erictraut I have the following test case which seems to also have ceased working after 1.1.309, and seems related: from __future__ import annotations
from dataclasses import dataclass
from typing import Callable, Generic, ParamSpec
P = ParamSpec("P")
@dataclass
class TaskDeclaration(Generic[P]):
func: Callable[P, None]
def enqueue(self, something: str, *args: P.args, **kwargs: P.kwargs) -> None:
pass
def task() -> Callable[[Callable[P, None]], TaskDeclaration[P]]:
def decorator(func: Callable[P, None]) -> TaskDeclaration[P]:
return TaskDeclaration(func)
return decorator
@task()
def test(a: int) -> None:
pass
test.enqueue("something") # Should have been test.enqueue("something", 3) to be valid Output with <=1.1.309: test.py:29:1 - error: Argument missing for parameter "a" (reportGeneralTypeIssues) |
@erictraut @rslinckx from typing import Callable, Generic, ParamSpec
P = ParamSpec("P")
T = TypeVar("T")
class Foo(Generic[P, T]):
...
class Bar(Generic[P, T]):
...
def fail() -> Callable[[Callable[P, T]], Foo[P, T]]:
...
def success() -> Callable[[Callable[P, T]], Callable[P, T]]:
...
def success2() -> Callable[[Foo[P, T]], Bar[P, T]]:
...
reveal_type(fail())
# Type of "fail()" is "((**P@fail) -> T@fail) -> Foo[(...), T@fail]"
reveal_type(success())
# Type of "success()" is "((**P@success) -> T@success) -> ((**P@success) -> T@success)"
reveal_type(success2())
# Type of "success2()" is "(Foo[P@success2, T@success2]) -> Bar[P@success2, T@success2]" |
…tion that returns a callable with a ParamSpec that does not appear outside of the return type annotation. A previous fix didn't correctly handle the case that involved a class parameterized with a ParamSpec. This addresses #5283.
Ah, my bad. I missed a small detail that caused my previous fix not to work with a class parameterized with a ParamSpec, as with |
This comment was marked as spam.
This comment was marked as spam.
This is included in pyright 1.1.315, which I just published. It will also be included in this week's insiders release of pylance. |
Describe the bug
See code.
Pyright >1.1.309 starts having the bug
Pylance has the problem as well.
Code or Screenshots
The text was updated successfully, but these errors were encountered: