Skip to content

Reject covariant overriding of attributes #3208

Description

@JukkaL

Covariant overriding of attributes is allowed though it's clearly unsafe. Example:

classA:
x: floatclassB(A):
x: int# no error, though unsafedeff(a: A) ->None:
a.x=1.1b=B()
f(b)
b.x# float at runtime, though declared as int

Mypy should reject x: int in B. If this is actually what the programmer intended, they can use # type: ignore.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions