mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
d9bbb05a16
* Implement Optional required, when creating a ModelField(required=True), make it persist * Add test for nullable required * Improve formatting of Undefined custom object * Refactor field infer/creation with Undefined to make it idempotent Needed for when _type_analysis is re-run in Generics * Add PR changes * Increment/update tests with code review * Update/refactor Undefined implementation with code review * Fix BoolUndefined as string type for mypy, not runtime * Add docs about required Optional * Add explicit tests for Any * Apply code review requested changes * move tests out of test_validators.py
14 lines
281 B
Python
14 lines
281 B
Python
from typing import Optional
|
|
from pydantic import BaseModel, Field, ValidationError
|
|
|
|
class Model(BaseModel):
|
|
a: Optional[int]
|
|
b: Optional[int] = ...
|
|
c: Optional[int] = Field(...)
|
|
|
|
print(Model(b=1, c=2))
|
|
try:
|
|
Model(a=1, b=2)
|
|
except ValidationError as e:
|
|
print(e)
|