Source code for jgdv._abstract.protocols.pydantic

 1#!/usr/bin/env python3
 2"""
 3
 4
 5"""
 6# Imports:
 7from __future__ import annotations
 8
 9# ##-- stdlib imports
10import datetime
11import enum
12import functools as ftz
13import itertools as itz
14import logging as logmod
15import pathlib as pl
16import re
17import time
18import types
19import collections
20import contextlib
21import hashlib
22from copy import deepcopy
23from uuid import UUID, uuid1
24from weakref import ref
25import atexit # for @atexit.register
26import faulthandler
27# ##-- end stdlib imports
28
29from pydantic import BaseModel
30
31# ##-- types
32# isort: off
33import abc
34import collections.abc
35from typing import TYPE_CHECKING, cast, assert_type, assert_never
36from typing import Generic, NewType
37# Protocols:
38from typing import Protocol, runtime_checkable
39# Typing Decorators:
40from typing import no_type_check, final, override, overload
41if TYPE_CHECKING:
42    from jgdv import Maybe
43    from typing import Final
44    from typing import ClassVar, Any, LiteralString
45    from typing import Never, Self, Literal
46    from typing import TypeGuard
47    from collections.abc import Iterable, Iterator, Callable, Generator
48    from collections.abc import Sequence, Mapping, MutableMapping, Hashable
49
50##--|
51
52# isort: on
53# ##-- end types
54
55##-- logging
56logging = logmod.getLogger(__name__)
57##-- end logging
58
59# Vars:
60ProtoMeta       = type(Protocol)
61PydanticMeta    = type(BaseModel)
62# Body:
[docs] 63class ProtocolModelMeta(ProtoMeta, PydanticMeta): 64 """ Use as the metaclass for pydantic models which are explicit Protocol implementers 65 66 eg: 67 68 class Example(BaseModel, ExampleProtocol, metaclass=ProtocolModelMeta):... 69 70 """ 71 pass