mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
3ec35590f1
* Support `Field` in `dataclass` + `'metadata'` kwarg of `dataclasses.field` Please enter the commit message for your changes. Lines starting * add `__has_field_info_default__` for minimal effect on perf * lower complexity of `_process_class`
22 lines
554 B
Python
22 lines
554 B
Python
import dataclasses
|
|
from typing import List, Optional
|
|
|
|
from pydantic import Field
|
|
from pydantic.dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class User:
|
|
id: int
|
|
name: str = 'John Doe'
|
|
friends: List[int] = dataclasses.field(default_factory=lambda: [0])
|
|
age: Optional[int] = dataclasses.field(
|
|
default=None,
|
|
metadata=dict(title='The age of the user', description='do not lie!')
|
|
)
|
|
height: Optional[int] = Field(None, title='The height in cm', ge=50, le=300)
|
|
|
|
|
|
user = User(id='42')
|
|
print(user.__pydantic_model__.schema())
|