Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Consider allowing frozendicts to be assigned to instance dicts #145119

Copy link
Copy link
@rhettinger

Description

@rhettinger
Issue body actions

Currently, can make an assignment to an instance's __dict__ attribute but the value must be an actual dict. It should allow frozendict as well.

This would be useful for making immutable instances without the awkward work arounds used in frozen dataclasses.

>>> class Point:
...     def __init__(self, x, y):
...         self.__dict__ = frozendict(x=x, y=y)
...
        
>>> p = Point(10, 20)
Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    p = Point(10, 20)
  File "<pyshell#52>", line 3, in __init__
    self.__dict__ = frozendict(x=x, y=y)
TypeError: __dict__ must be set to a dictionary, not a 'frozendict'

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
    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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.