File: root_model.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 (19 lines) | stat: -rw-r--r-- 406 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
from typing_extensions import assert_type

from pydantic import RootModel

IntRootModel = RootModel[int]

int_root_model = IntRootModel(1)
bad_root_model = IntRootModel('1')  # type: ignore[arg-type]  # pyright: ignore[reportArgumentType]

assert_type(int_root_model.root, int)


class StrRootModel(RootModel[str]):
    pass


str_root_model = StrRootModel(root='a')

assert_type(str_root_model.root, str)