-
Notifications
You must be signed in to change notification settings - Fork 15
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
pydantic compatible types #175
Comments
Hi @xneanq, thanks for opening this issue. Regarding
That said, Pydantic compatibility seems like a good idea, considering its popularity 👍 . What would needed to be implement in order to be pydantic-compatible? Perhaps some kind of patching can be done 🤔 |
looking at the pendulum_dt.py in pydantic-extra-types it looks like a few methods would need to be implemented which look fairly simple I'm not sure the neatest was to proceed, my first thoughts revolve around a mixin class implementing the required methods conditional on pydantic being available perhaps via extras |
At the moment, my preferred way would be to add the required methods directly to the This may take some time to implement though, as I want to do make sure it integrates well with pydantics customization options. If you need pydantic support today, the best solution would be to use |
Looking at # pydantic_extra_types/whenever.py
from whenever import LocalDateTime as _LocalDateTime
from typing import Annotated
class _LocalDateTimePydanticAnnotation:
@classmethod
def __get_pydantic_core_schema__(...): ...
@classmethod
def __get_pydantic_json_schema__(...): ...
LocalDateTime = Annotated[_LocalDateTime, _LocalDateTimePydanticAnnotation] the result: from pydantic_extra_types.whenever import LocalDateTime
class MyModel(Model):
x: LocalDateTime
# still usable as a class
LocalDateTime.MIN # still works
LocalDateTime(2020, 1, 1) # also works note that in the long term, it'd always be nicer to do: from whenever import LocalDateTime
class MyPydanticModel(Model):
x: LocalDateTime # usable directly |
sounds like you've got the next release in the bag ;) |
@illphil well, I suppose it's a two-phase thing: |
Hi I was fiddling around trying to implement pydantic compatible subclasses of whenever classes potentially to add to pydantic-extra-types but they're marked @Final
What's the reason for them to be @Final?
Any chance you would implement pydantic methods or lift the @Final restriction?
The text was updated successfully, but these errors were encountered: