Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mikeshardmind opened this issue Sep 12, 2023 · 1 comment
Open

Comments

@mikeshardmind
Copy link

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

@connernilsen
Copy link
Contributor

Hey @mikeshardmind, thanks for reporting this to us! I think this is something that we have run into trouble with before, but we didn't have the capacity at the time to implement a fix. I'll go through and see if it's something we're interested in coming back to, but either way, I'll add it to our backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants