-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-102578: Optimise setting and deleting mutable attributes on non-dataclass subclasses of frozen dataclasses #102573
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
776843d
Use `set`-based name lookup rather than `tuple`s for frozen dataclasses
XuehaiPan 0a400c1
Merge branch 'main' into dataclasses-lookup
XuehaiPan 54dd9c3
Add news entry
XuehaiPan 845c8ff
Update new entry
XuehaiPan 0f0d97c
Use empty tuple singleton in simple case
XuehaiPan 0524ee4
Update new entry
XuehaiPan 4055fa3
Add more details about the change in news entry
XuehaiPan 0bbf3a8
Update news entry
XuehaiPan 05eae2c
Merge branch 'main' into dataclasses-lookup
XuehaiPan b90d251
Eliminate unnecessary check for empty fields
XuehaiPan d3c8403
Remove mistake from auto import
XuehaiPan 84b5bdd
Add test for empty frozen dataclass
XuehaiPan 2d38e9c
Add test for empty frozen dataclass
XuehaiPan ef8e83f
Add test for empty frozen dataclass
XuehaiPan 5da787e
Add extra check for the exception type
XuehaiPan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Library/2023-03-10-13-21-16.gh-issue-102578.-gujoI.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Speed up setting or deleting mutable attributes on non-dataclass subclasses of | ||
frozen dataclasses. Due to the implementation of ``__setattr__`` and | ||
``__delattr__`` for frozen dataclasses, this previously had a time complexity | ||
of ``O(n)``. It now has a time complexity of ``O(1)``. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it matters much, but the zero length case could just avoid the
or name in ...
test entirely. Maybe fields_str should become fields_test, and then set it toor name in {<<generated set literal>>}
or set it to an empty string if there are no fields. Then change the generated code tof'if type(self) is cls {fields_test}:'
Although that doesn't read very well. Maybe tweak fields_test to be something else.This could be part of a different PR, or include it here. But in any event I'm not positive that the zero length case actually has a test. We should make sure it does for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a small test for empty frozen dataclass.