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

DM-45281: Add new timedelta data types for Pydantic models #269

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

rra
Copy link
Member

@rra rra commented Jul 16, 2024

Take advantage of the new functional validator support in Pydantic v2 and encapsulate custom timedelta validation as reusable types. The SecondsTimedelta type accept integer or floating-point number of seconds, possibly stringified. The HumanTimedelta type accepts the same, plus the duration strings accepted by parse_timedelta.

Unfortunately, sphinx-automodapi apparently doesn't recognize TypeAlias objects as something for which documentation should be generated, even with :include-all-objects:, so references to these new types have to be ignored when generating documentation.

@rra rra requested a review from jonathansick July 16, 2024 22:47
Take advantage of the new functional validator support in Pydantic v2
and encapsulate custom timedelta validation as reusable types. The
SecondsTimedelta type accept integer or floating-point number of
seconds, possibly stringified. The HumanTimedelta type accepts the
same, plus the duration strings accepted by parse_timedelta.

Unfortunately, sphinx-automodapi apparently doesn't recognize TypeAlias
objects as something for which documentation should be generated, even
with :include-all-objects:, so references to these new types have to
be ignored when generating documentation.
@rra rra force-pushed the tickets/DM-45281 branch from cfb17e9 to 2b826c2 Compare July 16, 2024 23:05
Copy link
Member

@jonathansick jonathansick left a comment

Choose a reason for hiding this comment

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

The pydantic functional validators do seem like a natural solution and a replacement for the custom types that I was sometimes implementing previously in Pydantic 1. Its too bad that they can't be documented automatically.

@rra rra merged commit d1864e6 into main Jul 18, 2024
6 checks passed
@rra rra deleted the tickets/DM-45281 branch July 18, 2024 00:21
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

Successfully merging this pull request may close these issues.

2 participants