-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Simplify
SchemaBase.copy
(#3543)
* refactor: Fix `C901` complexity in `SchemaBase.copy` 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. * refactor: Further simplify `SchemaBase.copy` 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 * refactor(perf): Merge identical `_shallow_copy` branches 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 * refactor(perf): Reduce `_deep_copy` - 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
- Loading branch information
1 parent
635a2ec
commit c9f9438
Showing
2 changed files
with
88 additions
and
92 deletions.
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
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