question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

parse_generic method to allow parsing non Model types

See original GitHub issue

Feature 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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
samuelcolvincommented, Oct 17, 2018

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:

  • at an interface between different components to provide a hard check of types
  • in development and testing to validate your code, then disable it to just a pass-through decorator in production

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

0reactions
dnp1commented, Oct 17, 2018

Agreed!

Thank you!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found