33This is used to ensure compatibility when one or more of the libraries are installed.
44"""
55
6- from __future__ import annotations
7-
86from enum import Enum
97from typing import (
108 Any ,
@@ -30,21 +28,58 @@ class DataclassProtocol(Protocol):
3028T_co = TypeVar ("T_co" , covariant = True )
3129
3230try :
33- from pydantic import BaseModel , FailFast , TypeAdapter
31+ from pydantic import (
32+ BaseModel ,
33+ FailFast , # pyright: ignore[reportGeneralTypeIssues,reportAssignmentType]
34+ TypeAdapter ,
35+ )
3436
3537 PYDANTIC_INSTALLED = True
3638except ImportError :
39+ from dataclasses import dataclass
3740
3841 @runtime_checkable
3942 class BaseModel (Protocol ): # type: ignore[no-redef]
4043 """Placeholder Implementation"""
4144
4245 model_fields : ClassVar [dict [str , Any ]]
4346
44- def model_dump (self , * args : Any , ** kwargs : Any ) -> dict [str , Any ]:
47+ def model_dump (
48+ self ,
49+ / ,
50+ * ,
51+ include : "Optional[Any]" = None ,
52+ exclude : "Optional[Any]" = None ,
53+ context : "Optional[Any]" = None ,
54+ by_alias : bool = False ,
55+ exclude_unset : bool = False ,
56+ exclude_defaults : bool = False ,
57+ exclude_none : bool = False ,
58+ round_trip : bool = False ,
59+ warnings : "Union[bool, Literal['none', 'warn', 'error']]" = True ,
60+ serialize_as_any : bool = False ,
61+ ) -> "dict[str, Any]" :
4562 """Placeholder"""
4663 return {}
4764
65+ def model_dump_json (
66+ self ,
67+ / ,
68+ * ,
69+ include : "Optional[Any]" = None ,
70+ exclude : "Optional[Any]" = None ,
71+ context : "Optional[Any]" = None ,
72+ by_alias : bool = False ,
73+ exclude_unset : bool = False ,
74+ exclude_defaults : bool = False ,
75+ exclude_none : bool = False ,
76+ round_trip : bool = False ,
77+ warnings : "Union[bool, Literal['none', 'warn', 'error']]" = True ,
78+ serialize_as_any : bool = False ,
79+ ) -> str :
80+ """Placeholder"""
81+ return ""
82+
4883 @runtime_checkable
4984 class TypeAdapter (Protocol [T_co ]): # type: ignore[no-redef]
5085 """Placeholder Implementation"""
@@ -53,9 +88,9 @@ def __init__(
5388 self ,
5489 type : Any , # noqa: A002
5590 * ,
56- config : Any | None = None ,
91+ config : "Optional[ Any]" = None ,
5792 _parent_depth : int = 2 ,
58- module : str | None = None ,
93+ module : "Optional[ str]" = None ,
5994 ) -> None :
6095 """Init"""
6196
@@ -64,42 +99,56 @@ def validate_python(
6499 object : Any , # noqa: A002
65100 / ,
66101 * ,
67- strict : bool | None = None ,
68- from_attributes : bool | None = None ,
69- context : dict [str , Any ] | None = None ,
70- ) -> T_co :
102+ strict : "Optional[bool]" = None ,
103+ from_attributes : "Optional[bool]" = None ,
104+ context : "Optional[dict[str, Any]]" = None ,
105+ experimental_allow_partial : "Union[bool, Literal['off', 'on', 'trailing-strings']]" = False ,
106+ ) -> "T_co" :
71107 """Stub"""
72108 return cast ("T_co" , object )
73109
74- @runtime_checkable
75- class FailFast ( Protocol ) : # type: ignore[no-redef]
110+ @dataclass
111+ class FailFast : # type: ignore[no-redef]
76112 """Placeholder Implementation for FailFast"""
77113
78- def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
79- """Init"""
114+ fail_fast : bool = True
80115
81116 PYDANTIC_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
82117
83118try :
84119 from msgspec import (
85120 UNSET ,
86121 Struct ,
87- UnsetType , # pyright: ignore[reportAssignmentType]
122+ UnsetType , # pyright: ignore[reportAssignmentType,reportGeneralTypeIssues ]
88123 convert ,
89124 )
90125
91126 MSGSPEC_INSTALLED : bool = True
92127except ImportError :
93128 import enum
129+ from collections .abc import Iterable
130+ from typing import TYPE_CHECKING , Callable , Optional , Union
131+
132+ if TYPE_CHECKING :
133+ from collections .abc import Iterable
94134
95135 @dataclass_transform ()
96136 @runtime_checkable
97137 class Struct (Protocol ): # type: ignore[no-redef]
98138 """Placeholder Implementation"""
99139
100- __struct_fields__ : ClassVar [tuple [str , ...]]
101-
102- def convert (* args : Any , ** kwargs : Any ) -> Any : # type: ignore[no-redef]
140+ __struct_fields__ : "ClassVar[tuple[str, ...]]"
141+
142+ def convert ( # type: ignore[no-redef]
143+ obj : Any ,
144+ type : "Union[Any, type[T]]" , # noqa: A002
145+ * ,
146+ strict : bool = True ,
147+ from_attributes : bool = False ,
148+ dec_hook : "Optional[Callable[[type, Any], Any]]" = None ,
149+ builtin_types : "Union[Iterable[type], None]" = None ,
150+ str_keys : bool = False ,
151+ ) -> "Union[T, Any]" :
103152 """Placeholder implementation"""
104153 return {}
105154
@@ -124,11 +173,11 @@ class DTOData(Protocol[T]): # type: ignore[no-redef]
124173 def __init__ (self , backend : Any , data_as_builtins : Any ) -> None :
125174 """Placeholder init"""
126175
127- def create_instance (self , ** kwargs : Any ) -> T :
176+ def create_instance (self , ** kwargs : Any ) -> "T" :
128177 """Placeholder implementation"""
129178 return cast ("T" , kwargs )
130179
131- def update_instance (self , instance : T , ** kwargs : Any ) -> T :
180+ def update_instance (self , instance : "T" , ** kwargs : Any ) -> "T" :
132181 """Placeholder implementation"""
133182 return cast ("T" , kwargs )
134183
0 commit comments