mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
c38c463137
* feat: add `Config.smart_union` to prevent coercion in `Union` if possible * docs: write some documentation * Update docs/usage/model_config.md Thanks @djpugh Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com> * improve doc * support 3.10 * improve smart_union * Update docs/usage/types.md Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com> * put new sentence inside warning block * docs: reorder * rename is_union_origin into is_union * inverse and condition for perf * fix doc Co-authored-by: David J Pugh <6003255+djpugh@users.noreply.github.com>
23 lines
270 B
Python
23 lines
270 B
Python
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()))
|