Open laurens-teirlynck opened 11 months ago
Hi @laurens-teirlynck,
Thanks for submitting this feature request. Seems reasonable - I'd be more than happy to review a PR adding this feature 😄. Is this something you'd be interested in opening a PR for?
Sure, I don't mind giving this a go
@laurens-teirlynck,
Maybe something that would make more sense in pydantic-extra-types
Is it correct that supporting this in pydantic-extra-types
would require a new Python class? ZoneInfo
and TzInfo
already exist, and it would be nice to be able to use one of those two.
Hi @laurens-teirlynck,
Yep, you'd want to create a type that subclasses from ZoneInfo
and implements like __get_pydantic_core_schema__
and __get_pydantic_json_schema__
.
You can also take this approach in order to support ZoneInfo
in your own project in the meantime! I'm going to move this issue over to pydantic-extra-types
😄
Initial Checks
Description
I feel like it should be possible to create a
BaseModel
with aZoneInfo
(or pydantic'sTzInfo
) like in the snippet below. If you try to run this, aPydanticSchemaGenerationError
is raised. https://github.com/pydantic/pydantic/issues/4987 reported the same thing, but was closed by the author after working around the issue.Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM mode