reagento / adaptix

An extremely flexible and configurable data model conversion library.
https://adaptix.readthedocs.io
Apache License 2.0
362 stars 24 forks source link

Workaround for stringified TypedDict fields #227

Closed zhPavel closed 6 months ago

zhPavel commented 6 months ago

There is python bug https://github.com/python/cpython/issues/97727. If field of TypedDict is stringified or from __future__ import annotations is placed in file Required and NotRequired specifiers is ignored when __required_keys__ and __optional_keys__ is calculated. This bug can not be fixed by python because such annotations such be evaluted lazily.

TypedDict's introspection have to exclude fields wrapped with NotRequired from __required_keys__ and Required from __optional_keys__. NotRequired and Required can be wrapped via Annotated, so implementation should use normalize_type and recursively search for specifier.