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>
15 lines
235 B
Python
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]))
|