parse_generic method to allow parsing non Model types
See original GitHub issueFeature Request
I’m writting a middleware for aiohttp that uses pydantic (inspired by webargs that uses marshmallow), see
The development is still in the beggining
I would appreciate an additional helper functions for parsing types like:
List[Model] # where model is a pydantic model
Dict[int, List[Model]]
and several other derivations of generic types. Do you think make sense for pydantic scope, provides a function like:
def parse_object_into_generic(type: Union[GenericType, Type], object) -> Any:
pass
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
parse_generic method to allow parsing non Model types #278
Feature Request I'm writting a middleware for aiohttp that uses pydantic (inspired by webargs that uses marshmallow), see The development is ...
Read more >How do I parse generic data types from a file? - Stack Overflow
I want to implement a generic method to read data from a file and populate the data fields of this class. Something like:...
Read more >Custom data conversion and sorting - IBM
Use this information to learn about data formatting, parsing, validation, and sorting behavior in the Cúram web application. Custom data conversion and sorting ......
Read more >pydantic Changelog - pyup.io
Allow type checkers to infer inner type of `Json` type. ... Fix MyPy plugin to not override pre-existing `__init__` method in models, 3824...
Read more >A Guide To Parsing: Algorithms And Terminology
In the case of parsing you have to determine the model from the raw representation ... Parsing allows to transform data in a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Makes more sense, longer term I’m thinking about a pydantic decorator for validating types. The idea is you could use it in multiple scenarios:
I’m not expecting to work on that in the immediate future. However it shouldn’t be very hard to build your own logic for this, take a look at how dataclasses are validation for inspiration:
https://github.com/samuelcolvin/pydantic/blob/cd50601172462b49cdf09e4d988906ba8f14af87/pydantic/dataclasses.py#L32-L34
Agreed!
Thank you!