Files
pydantic/docs/examples/model_config_smart_union_on_edge_case.py
T
Eric Jolibois c38c463137 feat: add Config.smart_union option (#2092)
* 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>
2021-12-07 21:58:52 +00:00

15 lines
235 B
Python

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]))