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

[Bug]: Typing inconsistency between PyRight and myPy #142

Closed
1 task
maxfischer2781 opened this issue May 23, 2024 · 0 comments · Fixed by #145
Closed
1 task

[Bug]: Typing inconsistency between PyRight and myPy #142

maxfischer2781 opened this issue May 23, 2024 · 0 comments · Fixed by #145
Assignees
Labels
bug Something isn't working

Comments

@maxfischer2781
Copy link
Owner

What happened?

As per the "Static Checks" action, type checking via PyRight is currently failing:

build: asyncstdlib/contextlib.pyi#L77
Type annotation for "self" parameter of "init" method cannot contain class-scoped type variables (reportInvalidTypeVarUse)

This is due to a recent change in the typing spec which has been picked up by PyRight but not MyPy yet. MyPy may fix this in python/mypy#17239, but the status is unclear to me. TypeShed had the same problem (python/typeshed#11780) and has resorted to just # pyright: ignore[reportInvalidTypeVarUse] everything (python/typeshed#11810).

There is only a single error in asyncstdlib, so ignoring the error for now may be viable.

Minimal Reproducible Example

from typing import Generic, TypeVar

TC = TypeVar("TC")
TA = TypeVar("TA")

class MyPy(Generic[TC]):  # vvv fails for pyright: Type annotation for "self" parameter of "__init__" method cannot contain class-scoped type variables
    def __init__(self: "MyPy[TC]", val: TC) -> None: ...

class PyRight(Generic[TC]):
    def __init__(self: "PyRight[TA]", val: TA) -> None: ...

reveal_type(PyRight(12))  # fails for mypy: "playground.PyRight[TA`-1]"

Request Assignment [Optional]

  • I already understand the cause and want to submit a bugfix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant