Skip to content

Instance.__dict__ is read-only #2139

@prusnak

Description

@prusnak

Micropython:

>>> class Foo:
...     pass
>>> t = Foo()
>>> t.__dict__
{}
>>> t.__dict__['a'] = 4
>>> t.__dict__
{}
>>> t.a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'a'

Python3:

>>> class Foo:
...     pass
... 
>>> t = Foo()
>>> t.__dict__
{}
>>> t.__dict__['a'] = 4
>>> t.__dict__
{'a': 4}
>>> t.a
4

Same applies for t.__dict__.update(another_dict)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions