Skip to content
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

refactor: Simplify SchemaBase.copy #3543

Merged
merged 4 commits into from
Aug 18, 2024

Commits on Aug 18, 2024

  1. 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.
    dangotbanned committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    6d706ae View commit details
    Browse the repository at this point in the history
  2. 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
    dangotbanned committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    4ce42d9 View commit details
    Browse the repository at this point in the history
  3. 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
    dangotbanned committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    dcb34e9 View commit details
    Browse the repository at this point in the history
  4. 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
    dangotbanned committed Aug 18, 2024
    Configuration menu
    Copy the full SHA
    d0558d2 View commit details
    Browse the repository at this point in the history