mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
6b8d2babaaca420d20aab52bfe5f42cf5e382f1d
* Fix #947, fix #1483, fix #1247 allow inner type vars to be present in parent generic classes - Rename generics._is_type to _is_generic in response to comment: https://github.com/samuelcolvin/pydantic/pull/1989#discussion_r503400391 - Add more explicit type assertion in generics test - Add generics tests and unify naming - Move deep generic tests all into same place in code - Unify naming convention in deep generic tests using naming of existing tests - Add tests for multiple inheritance and multiple type vars - Add generic tests for type hint resolution cases - Fix edge cases for handling parameters in generic models - Resolve parameters correctly - Add tests for special cases like callables - Add returning generic type directly if parameters and arguments are identical. * Apply review comments - Add docstrings - Small refactor `generics.__concrete_name__` - Small refactor of `generics.resolve_type_hints` - Change `is_identity_typevars_map` to more generic and clearer `all_identical` and move into utils. - rename "resolve_type_hint" to "replace_types" so as to not get confused with "resolve_annotations" from `pydantic.typing` * Fix generics test coverage * Update pydantic/generics.py, remove unneeded annotation mypy understands list comprehensions as they are now Co-authored-by: Eric Jolibois <em.jolibois@gmail.com> Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
build(deps): bump to pytest 6.2.1, pytest-mock 3.4.0, mkdocs-material 6.1.7 and codecov-action v1.0.15 (#2201)
pydantic
Data validation and settings management using Python type hinting.
Fast and extensible, pydantic plays nicely with your linters/IDE/brain. Define how data should be in pure, canonical Python 3.6+; validate it with pydantic.
Help
See documentation for more details.
Installation
Install using pip install -U pydantic or conda install pydantic -c conda-forge.
For more installation options to make pydantic even faster,
see the Install section in the documentation.
A Simple Example
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel
class User(BaseModel):
id: int
name = 'John Doe'
signup_ts: Optional[datetime] = None
friends: List[int] = []
external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}
user = User(**external_data)
print(user)
#> User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
print(user.id)
#> 123
Contributing
For guidance on setting up a development environment and how to make a contribution to pydantic, see Contributing to Pydantic.
Reporting a Security Vulnerability
See our security policy.
Languages
Python
99.7%
Makefile
0.3%