File: misc.py

package info (click to toggle)
pydantic 2.12.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,640 kB
  • sloc: python: 75,984; javascript: 181; makefile: 115; sh: 38
file content (30 lines) | stat: -rw-r--r-- 567 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pydantic import BaseModel


class Sub(BaseModel):
    a: int
    b: int


class Model(BaseModel):
    subs: list[Sub]


def func(model: Model) -> None:
    model.model_dump(
        include={'a': {1: True}},
    )
    model.model_dump(
        include={'a': {'__all__': True}},
    )
    model.model_dump(
        include={'a': {1: {'a'}}},
    )
    model.model_dump(
        include={'a': {1, 2}},
    )

    # Invalid cases, should fail but the `IncEx` alias uses `bool` due to mypy limitations:
    model.model_dump(
        include={'a': {1: False}},
    )