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

Simplify Element type by use of Pydantic? #3702

Open
ctrahey opened this issue Oct 5, 2024 · 1 comment
Open

Simplify Element type by use of Pydantic? #3702

ctrahey opened this issue Oct 5, 2024 · 1 comment

Comments

@ctrahey
Copy link

ctrahey commented Oct 5, 2024

This can be thought of as a request for a chore rather than an issue.

Pydantic would simplify the first 150 lines of this section of code down to about 50 but more importantly, drop the number of places an author would need to touch when adding/modifying a field from 3 to 1.

There are also improvements to be expected in other use cases, like serialization and other downstream uses that make reference to this type.

class ElementMetadata:
"""Fully-dynamic replacement for dataclass-based ElementMetadata."""
# NOTE(scanny): To add a field:
# - Add the field declaration with type here at the top. This makes it a "known" field and
# enables type-checking and completion.
# - Add a parameter with default for field in __init__() and assign it in __init__() body.
# - Add a consolidation strategy for the new field in
# `ConsolidationStrategy.field_consolidation_strategies()` below. This strategy will be used
# to consolidate this new metadata field from each pre-chunk element during chunking.
# - Add field-name to DEBUG_FIELD_NAMES if it shouldn't appear in dict/JSON or participate in
# equality comparison.

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

No branches or pull requests

2 participants
@ctrahey and others