Skip to content

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

Closed

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 :)

Activity

  1. ilevkivskyi commented on Mar 6, 2019

    @ilevkivskyi
    Member

    I think this is essentially a duplicate of #4547

  2. ashb commented on Mar 6, 2019

    @ashb
    Author

    Could be yes - I'm not familiar enough with Mypy to say, and I thought it might have been specific to having three classes in the hierarchy, and I got a different error message.

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

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