Skip to content

Inconsist with cpython in deleting __dict__ #5355

Description

@Mskxn

In CPython, the following code can execute normally.

class Foo: pass
f = Foo()
print(f.__dict__)
del f.__dict__

But in rustpython, it triggers TypeError:

Traceback (most recent call last):
File "temp.py", line 4, in <module>
                  del f.__dict__
TypeError: can't delete attribute

I am not sure if it is a design or a bug.
P.S., Are there any docs to explain the consistency between CPython and rustpython, or they should be exactly the same?

Activity

  1. added
    good first issue
    C-compat
    on Jul 18, 2024
  2. youknowone commented on Jul 18, 2024

    @youknowone
    Member

    I expect that eventually be the same.

    I never expect this is possible in CPython.
    So this is the way to "clear" __dict__.

  3. Mskxn commented on Jul 18, 2024

    @Mskxn
    Author

    It seems that del __dict__ is always possible in CPython (I have tried on CPython 3.10), but some relative tests have been introduced recently (3.13):
    https://github.com/python/cpython/blob/81fd625b5c30cc6f417c93bad404923676ad8ca3/Lib/test/test_class.py#L817

  4. youknowone commented on Jul 18, 2024

    @youknowone
    Member

    For contributors:
    current object_set_dict function signature doesn't support delete.
    Changing it to pub fn object_set_dict(obj: PyObjectRef, dict: PySetterValue<PyDictRef>, vm: &VirtualMachine) -> PyResult<()> is the starting point.
    The remaining steps will be straight-forward by understanding how PySetterValue looks like.

  5. fanninpm commented on Nov 27, 2024

    @fanninpm
    Contributor

    Just checking — did #5436 actually fix this issue?

  6. maxweilun1989 commented on Dec 12, 2024

    @maxweilun1989

    @fanninpm I tried this on the latest commit and found that the issue hasn’t been resolved yet. Could you assign it to me?"

  7. added a commit that references this issue on Apr 30, 2026
    f90a5cf
  8. added a commit that references this issue on Sep 16, 2026
    ddb5125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-stdlibC-compat

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions