Skip to content

Type of class variable from "grandparent" is replaced by untyped-subclass #6511

Closed
@ashb

Description

@ashb

Minimal repro case:

from typing import Iterable

class A:
    a: Iterable[str] = ("a", )

class B(A):
    a = ("a", "b")

class C(B):
    a = ("a", "b", "c")

And the error:

a.py:10: error: Incompatible types in assignment (expression has type "Tuple[str, str, str]", base class "B" defined the type as "Tuple[str, str]")

The error is reported on the assignment in C.

I would have expected that B.a would have the same type as A.a since B.a doesn't have an explicit type.

Maybe relates to #4547 or #2510, or maybe I'm just expecting mypy to do something that it won't :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions