Merged
Conversation
The nested functions do not reference `self` and can be split out, much like `.to_dict` -> `_todict`. Saw this as a chance to add annotations as well. I think this helps illustrate that `.copy` is a noop for anything other than `SchemaBase | dict | list` - which I think might need to be addressed in the future.
10 lines shorter and is no longer constrained to `list` on the assert. May be slightly faster on `python<3.11` which do not have zero-cost exceptions https://docs.python.org/3.11/whatsnew/3.11.html#misc
Remembered a related `ruff` rule [FURB145](https://docs.astral.sh/ruff/rules/slice-copy/). Wouldn't have made this fix, but likely would have led someone there
- Initialize an empty set **once** at origin, rather than creating a new list per iteration - Renamed to `by_ref` in the new private function, to better describe the operation. - No change to public API. - Define a partial `copy` to reduce repetition - Use a genexpr for `args`, to avoid unpacking twice
binste
approved these changes
Aug 18, 2024
Contributor
binste
left a comment
There was a problem hiding this comment.
LGTM, thanks @dangotbanned!
Member
Author
Thanks @binste |
This was referenced Aug 21, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related
C901complexity #3531Description
This PR addresses one complex-structure violation, adds some typing, and gives a little performance boost in
SchemaBase.copy.See each commit message for more detail on specific changes.
Last commit message (auto-added)
by_refin the new private function, to better describe the operation.copyto reduce repetitionargs, to avoid unpacking twice