8000 bpo-45897: Fix frozen-slotted dataclass bug by AlexWaygood · Pull Request #29895 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45897: Fix frozen-slotted dataclass bug #29895

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

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more comments
  • Loading branch information
AlexWaygood authored Dec 16, 2021
commit eda3c7f38cd94ea14812d8908902172d06a5f75e
5 changes: 5 additions & 0 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ def _frozen_get_del_attr(cls, fields, globals):
else:
# Special case for the zero-length tuple.
fields_str = '()'

# bpo-45897: Do not raise FrozenInstanceError
# if the dataclass has slots & the attribute is not specified in __slots__.
# Instead, let the standard __slots__ machinery raise AttributeError naturally
# in the super(cls, self).__setattr__ call
return (_create_fn('__setattr__',
('self', 'name', 'value'),
(f'if "__slots__" in cls.__dict__ and name not in cls.__slots__:',
Expand Down
0