@@ -19,9 +19,10 @@ class NotLoaded:
1919except ImportError :
2020 pydantic = None
2121
22- # moved the not implemented versions of Checked* classes in the beginning of the module
23- # otherwise PyCharm do not provide auto-completion for methods of CheckedSession
24- # (imported from Session)
22+
23+ # the not implemented versions of Checked* classes must be in the beginning of
24+ # the module otherwise PyCharm do not provide auto-completion for methods of
25+ # CheckedSession (imported from Session)
2526if not pydantic :
2627 def CheckedArray (axes : AxisCollection , dtype : np .dtype = float ) -> Type [Array ]:
2728 raise NotImplementedError ("CheckedArray cannot be used because pydantic is not installed" )
@@ -97,12 +98,13 @@ def validate_array(value: Any, info: ValidationInfo) -> Array:
9798
9899 return Annotated [Array , BeforeValidator (validate_array )]
99100
101+
100102 class AbstractCheckedSession :
101103 pass
102104
105+
103106 # Simplified version of the ModelMetaclass class from pydantic:
104107 # https://github.com/pydantic/pydantic/blob/v2.12.0/pydantic/_internal/_model_construction.py
105-
106108 class ModelMetaclass (ABCMeta ):
107109 @no_type_check # noqa C901
108110 def __new__ (mcs , cls_name : str , bases : tuple [type [Any ], ...], namespace : dict [str , Any ], ** kwargs : Any ):
@@ -204,6 +206,7 @@ def __dir__(self) -> list[str]:
204206 attributes .remove ('__fields__' )
205207 return attributes
206208
209+
207210 class CheckedSession (Session , AbstractCheckedSession , metaclass = ModelMetaclass ):
208211 """
209212 Class intended to be inherited by user defined classes in which the variables of a model are declared.
0 commit comments