Skip to content

Incompatible definition of generic field on multiple base classes #9031

Closed
@dn-kialo

Description

@dn-kialo

[BUG] Edited for a clearer example
Given this code:

# mypy version 0.770
from typing import Generic, TypeVar

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

class A:
  foo: int

class B(Generic[T]):
  foo: T

class C(B[int], A):
  pass

reveal_type(A().foo)
reveal_type(B().foo)
reveal_type(C().foo)

I get this output:

example.py:11: error: Definition of "foo" in base class "B" is incompatible with definition in base class "A"
example.py:14: note: Revealed type is 'builtins.int'
example.py:15: note: Revealed type is 'builtins.int*'
example.py:16: note: Revealed type is 'builtins.int*'

I couldn't find what builtins.int*. The code makes sense though, right?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions