forked from pydantic/pydantic
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into pydanticGH-3444
- Loading branch information
Showing
43 changed files
with
991 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add `confrozenset()`, analogous to `conset()` and `conlist()` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add parameterised subclasses to `__bases__` when constructing new parameterised classes, so that `A <: B => A[int] <: B[int]`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add `Config.smart_union` to prevent coercion in `Union` if possible. See [the doc](https://pydantic-docs.helpmanual.io/usage/model_config/#smart-union) for more information |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Set `minItems` and `maxItems` in generated JSON schema for fixed-length tuples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Try to evaluate forward refs automatically at model creation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Make serialization of referenced pydantic models possible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
`Enum` fields now properly support extra kwargs in schema generation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import List, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Address(BaseModel): | ||
city: str | ||
country: str | ||
|
||
|
||
class User(BaseModel): | ||
name: str | ||
address: Address | ||
friends: Optional[List['User']] = None | ||
|
||
class Config: | ||
json_encoders = { | ||
Address: lambda a: f'{a.city} ({a.country})', | ||
'User': lambda u: f'{u.name} in {u.address.city} ' | ||
f'({u.address.country[:2].upper()})', | ||
} | ||
|
||
|
||
User.update_forward_refs() | ||
|
||
wolfgang = User( | ||
name='Wolfgang', | ||
address=Address(city='Berlin', country='Deutschland'), | ||
friends=[ | ||
User(name='Pierre', address=Address(city='Paris', country='France')), | ||
User(name='John', address=Address(city='London', country='UK')), | ||
], | ||
) | ||
print(wolfgang.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from typing import Union | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Foo(BaseModel): | ||
pass | ||
|
||
|
||
class Bar(BaseModel): | ||
pass | ||
|
||
|
||
class Model(BaseModel): | ||
x: Union[str, int] | ||
y: Union[Foo, Bar] | ||
|
||
|
||
print(Model(x=1, y=Bar())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Union | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Foo(BaseModel): | ||
pass | ||
|
||
|
||
class Bar(BaseModel): | ||
pass | ||
|
||
|
||
class Model(BaseModel): | ||
x: Union[str, int] | ||
y: Union[Foo, Bar] | ||
|
||
class Config: | ||
smart_union = True | ||
|
||
|
||
print(Model(x=1, y=Bar())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import List, Union | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Model(BaseModel, smart_union=True): | ||
x: Union[List[str], List[int]] | ||
|
||
|
||
# Expected coercion | ||
print(Model(x=[1, '2'])) | ||
|
||
# Unexpected coercion | ||
print(Model(x=[1, 2])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,5 @@ class Foo(BaseModel): | |
sibling: Foo = None | ||
|
||
|
||
Foo.update_forward_refs() | ||
|
||
print(Foo()) | ||
print(Foo(sibling={'a': '321'})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
ansi2html==1.6.0 | ||
flake8==4.0.1 | ||
flake8-quotes==3.3.1 | ||
hypothesis==6.24.0 | ||
hypothesis==6.30.1 | ||
markdown-include==0.6.0 | ||
mdx-truly-sane-lists==1.2 | ||
mkdocs==1.2.3 | ||
mkdocs-exclude==1.0.2 | ||
mkdocs-material==7.3.4 | ||
mkdocs-material==8.0.5 | ||
sqlalchemy | ||
orjson | ||
ujson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.