mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
576e4a3a8d
* refactor: rewrite the whole pydantic dataclass logic * test: add tests for issue 2162 * test: add tests for issue 2383 * test: add tests for issue 2398 * test: add tests for issue 2424 * test: add tests for issue 2541 * test: add tests for issue 2555 * refactor: polish * change default and support 3.6 * fix coverage * fix mypy and text * typos * test: add tests for issue 2594 * fix: forward doc for schema description * add change * chore: small changes from review * refactor: avoid extra __pydantic_run_validation__ parameter * small tweaks * remove wrapper * support 3.6 * fix: mypy * rewrite doc * add docs * wrapper is removed now * a bit more docs * code review * faster dict update * add test for issue 3162 * add test for issue 3011 * feat: add `Config.post_init_after_validation` * allow config via dict * fix cython and TypedDict * chore: typo * move `compiled` in `version.py` * refactor: switch from `Config.post_init_after_validation` to \'post_init_call` * add dataclass isinstance support * avoid multi paragraphs in change file * feat: support `Config.extra` * refactor: simplify a bit code * refactor: avoid creating useless functions * refactor: simplify `is_builtin_dataclass` * support extra in post_init * docs: add warning on config extra * fix #3713 compatibility * update docs Co-authored-by: Samuel Colvin <s@muelcolvin.com>
27 lines
593 B
Python
27 lines
593 B
Python
from pydantic import ConfigDict
|
|
from pydantic.dataclasses import dataclass
|
|
|
|
|
|
# Option 1 - use directly a dict
|
|
# Note: `mypy` will still raise typo error
|
|
@dataclass(config=dict(validate_assignment=True))
|
|
class MyDataclass1:
|
|
a: int
|
|
|
|
|
|
# Option 2 - use `ConfigDict`
|
|
# (same as before at runtime since it's a `TypedDict` but with intellisense)
|
|
@dataclass(config=ConfigDict(validate_assignment=True))
|
|
class MyDataclass2:
|
|
a: int
|
|
|
|
|
|
# Option 3 - use a `Config` class like for a `BaseModel`
|
|
class Config:
|
|
validate_assignment = True
|
|
|
|
|
|
@dataclass(config=Config)
|
|
class MyDataclass3:
|
|
a: int
|