Skip to content

bad-override false positive for module-level TypeVar #4847

Description

@AdrianSosic

Describe the Bug

Pyrefly reports bad-override when a concrete class overrides a method whose signature uses a module-level TypeVar. The error message shows identical types on both sides of the "not assignable" claim, making this a self-contradictory false positive.

Minimal reproduction:

from typing import TypeVar
from typing_extensions import override

T = TypeVar("T", bound=int)

class Base:
    def method(self, x: T | None = None) -> T: ...

class Derived(Base):
    @override
    def method(self, x: T | None = None) -> T:
        raise NotImplementedError
pyrefly check repro.py --preset default

Output:

ERROR Class member `Derived.method` overrides parent class `Base` in an inconsistent manner [bad-override]
  `Derived.method` has type `[T: int](self: Derived, x: T | None = None) -> T`, which is not assignable to
  `[T: int](self: Derived, x: T | None = None) -> T`, the type of `Base.method`

Expected: No error. The types on both sides of "not assignable" are character-for-character identical.

Notes:

  • Reproduces under --preset default, --preset legacy, and --preset strict.
  • Does not reproduce under --preset basic, where override validation is disabled entirely.
  • mypy reports no errors on the same code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions