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

[mypyc] Only allow deleting attributes declared using __deletable__ #10524

Merged
merged 12 commits into from
Jun 6, 2021

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented May 22, 2021

Native classes now must declare attributes that can be deleted.

This improves type safety and will make it possible to support
always defined attributes in the future.

Example:

class C:
    x: int
    y: int
    z: int
    __deletable__ = ['x', 'y']

Now x and y can be deleted, but z can't be:

def f(c: C) -> None:
    del c.x  # Ok
    del c.y  # Ok
    del c.z  # Error

__deletable__ has no effect in non-native classes and their behavior is same
as before.

Closes mypyc/mypyc#853.

@JukkaL JukkaL merged commit b562cc2 into master Jun 6, 2021
@JukkaL JukkaL deleted the deletable branch June 6, 2021 17:27
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

Successfully merging this pull request may close these issues.

Make attributes of native classes not deletable by default
1 participant