Skip to content

Mutable attributes of classes should be invariant in subclasses. #789

Open
@mikeshardmind

Description

@mikeshardmind

Pyre Bug

Bug description

Subclasses should not be able to change the type of their mutable attributes, see relevant open issue in mypy and recent discussion in python/typing

Reproduction steps

class UStr(str):
    pass


class A:
    foo: str
    def __init__(self):
        self.foo = ""

class B(A):
    foo: UStr
    def __init__(self):
        self.foo = UStr("")

Expected behavior
Pyre should not allow the subclass B

Logs

No Errors!

Please run your reproduction steps followed by pyre rage > pyre_rage.log, and upload the file here:

Additional context
This was run in the playground to verify, as I am not a pyre user, only bringing this to the attention of pyre due to ecosystem impact

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions