zmievsa / pydantic-duality

Automatically and lazily generate three versions of your pydantic models: one with Extra.forbid, one with Extra.ignore, and one with all fields optional
https://ovsyanka83.github.io/pydantic-duality/
MIT License
31 stars 1 forks source link

Support for Python 3.8 and 3.9 #8

Closed r4victor closed 6 months ago

r4victor commented 6 months ago

Our project (https://github.com/dstackai/dstack) requires supporting all currently supported Python versions (https://devguide.python.org/versions/). This includes Python 3.8 and Python 3.9 not supported by pydantic-duality, which requires Python >= 3.10.

I think it would make a lot of sense for pydantic-duality to support all active Python versions since it's a library and can run in different Python environments. It's basically a requirement for a library wide adoption.

As far as I understand, pydantic-duality does not hard-depend on some Python >= 3.10 features. And the only thing that prevents it from working on Python 3.9 is the Usage of the typing union operator (|) (and some new annotation types handling in _resolve_annotation()). It's a little bit more work to support Python 3.8, but mostly it's importing types from typing_extensions.

pydantic-duality depends on https://github.com/zmievsa/cached_classproperty that claims to support Python >= 3.8 but works only on Python >= 3.10 for the same typing reason.

I suggest to introduce minimal changes required to support older Python versions. I'm willing to make the PRs.

zmievsa commented 6 months ago

Yeah, that makes sense. Will take a look this week.