-
Notifications
You must be signed in to change notification settings - Fork 791
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
feature: support JSON(typed_dict=TypedDict() ) Input, Output #3748
Comments
If we want to support TypedDict then it should just be supported by JSON and using the typing system, to some extend (but parsing types are costly, esp for IO descriptor as it will affect users throughput). TypedDict is only available from 3.8+ so this means we will have to depends on typing_extensions. From a quick glance from the implementation, it seems like you are just using Pydantic, so I don't see the point of having this as a part of the core library. The core usage of Pydantic is for validation. So if we want to support TypedDict and attrs class to an extend, it should probably be under the JSON IO descriptor. |
* (pyproject.toml) add dependency "io-json = [... "type-extensions"]" * (json.py) separate code block service.py(pydantic) and service.py(TypedDict) * (json.py) add validate "typeddict and pydantic_model are mutually exclusive" * (json.py) "if sys.version_info >= (3, 8):" * (json.py) explicit check () "if typeddict is not None and not is_typeddict(typeddict)"
* (json.py) check legacy_typeddict BadInput("You should use `typing_extensions.TypedDict` instead of `typing.TypedDict` with Python < 3.11.") * (json.py) refactor openapi_schema() & openapi_components() * (tests/unit/_internal/io/test_json.py) typeddict testcase * (utils.py) refactor typed_dict_to_schema() -> typed_dict_to_dict()
* (json.py) remove pydantic.is_legacy_typeddict() * (utils.py) remove useless import * (pyproject.toml) fix "type-extensions" to "typing-extensions"
* (json.py) remove pydantic.is_legacy_typeddict() * (utils.py) remove useless import * (pyproject.toml) fix "type-extensions" to "typing-extensions"
* (json.py) t.Type["TypedDict"] -> type[t.TypedDict]
* (json.py) update error msg & docs example
…o typeddict_title
This issue seems to be pointless in the current 1.2 version. |
Feature request
to be
as is
Motivation
If we use Pydantic just to specify a type schema without validation, the logic of
xx.dict()
->Pydantic.parse_obj()
unnecessary layer which can affect performance. In this case, using TypedDict seems necessary.here is POC #3749#3809
I'd like to hear your thoughts on TypedDict
Other
No response
The text was updated successfully, but these errors were encountered: