Skip to content

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

Closed
@maxfischer2781

Description

@maxfischer2781

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.

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions