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

Conversation

dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Aug 18, 2024

Related

Description

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)

  • 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

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
@dangotbanned dangotbanned marked this pull request as ready for review August 18, 2024 13:44
Copy link
Contributor

@binste binste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @dangotbanned!

@binste binste merged commit c9f9438 into vega:main Aug 18, 2024
14 checks passed
@dangotbanned
Copy link
Member Author

LGTM, thanks @dangotbanned!

Thanks @binste

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants