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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
import warnings
from abc import ABC, abstractmethod
from dataclasses import Field
from typing import (Any, ClassVar, Iterable, Callable, Collection, Sequence)
# added as we can't import from `type_def`, as we run into a circular import.
JSONObject = dict[str, Any]
def type_name(obj: type) -> str:
"""Return the type or class name of an object"""
def show_deprecation_warning(
fn: Callable | str,
reason: str,
fmt: str = "Deprecated function {name} ({reason})."
) -> None:
"""
Display a deprecation warning for a given function.
@param fn: Function which is deprecated.
@param reason: Reason for the deprecation.
@param fmt: Format string for the name/reason.
"""
class JSONWizardError(ABC, Exception):
"""
Base error class, for errors raised by this library.
"""
_TEMPLATE: ClassVar[str]
_parent_cls: type
_class_name: str | None
_default_class_name: str | None
def class_name(self) -> str | None: ...
# noinspection PyRedeclaration
def class_name(self) -> None: ... # type: ignore[no-redef]
def parent_cls(self) -> type | None: ...
# noinspection PyRedeclaration
def parent_cls(self, value: type | None) -> None: ... # type: ignore[no-redef]
@staticmethod
def name(obj) -> str: ...
@property
@abstractmethod
def message(self) -> str:
"""
Format and return an error message.
"""
def __str__(self) -> str: ...
class ParseError(JSONWizardError):
"""
Base error when an error occurs during the JSON load process.
"""
_TEMPLATE: str
obj: Any
obj_type: type
phase: str
ann_type: type | Iterable | None
base_error: Exception
kwargs: dict[str, Any]
_class_name: str | None
_default_class_name: str | None
_field_name: str | None
_json_object: Any | None
fields: Collection[Field] | None
def __init__(self, base_err: Exception,
obj: Any,
ann_type: type | Iterable | None,
phase: str,
_default_class: type | None = None,
_field_name: str | None = None,
_json_object: Any = None,
**kwargs):
...
@property
def field_name(self) -> str | None:
...
@property
def json_object(self):
...
@property
def message(self) -> str: ...
class ExtraData(JSONWizardError):
"""
Error raised when extra keyword arguments are passed in to the constructor
or `__init__()` method of an `EnvWizard` subclass.
Note that this error class is raised by default, unless a value for the
`extra` field is specified in the :class:`Meta` class.
"""
_TEMPLATE: str
class_name: str
extra_kwargs: Collection[str]
field_names: Collection[str]
def __init__(self,
cls: type,
extra_kwargs: Collection[str],
field_names: Collection[str]):
...
@property
def message(self) -> str: ...
class MissingFields(JSONWizardError):
"""
Error raised when unable to create a class instance (most likely due to
missing arguments)
"""
_TEMPLATE: str
obj: JSONObject
fields: list[str]
all_fields: tuple[Field, ...]
missing_fields: Collection[str]
base_error: Exception | None
missing_keys: Collection[str] | None
kwargs: dict[str, Any]
class_name: str
parent_cls: type
def __init__(self, base_err: Exception | None,
obj: JSONObject,
cls: type,
cls_fields: tuple[Field, ...],
cls_kwargs: JSONObject | None = None,
missing_fields: Collection[str] | None = None,
missing_keys: Collection[str] | None = None,
**kwargs):
...
@property
def message(self) -> str: ...
class UnknownKeysError(JSONWizardError):
"""
Error raised when unknown JSON key(s) are
encountered in the JSON load process.
Note that this error class is only raised when the
`raise_on_unknown_json_key` flag is enabled in
the :class:`Meta` class.
"""
_TEMPLATE: str
unknown_keys: list[str] | str
obj: JSONObject
fields: list[str]
kwargs: dict[str, Any]
class_name: str
def __init__(self,
unknown_keys: list[str] | str,
obj: JSONObject,
cls: type,
cls_fields: tuple[Field, ...],
**kwargs):
...
@property
@warnings.deprecated('use `unknown_keys` instead')
def json_key(self) -> list[str] | str: ...
@property
def message(self) -> str: ...
# Alias for backwards-compatibility.
UnknownJSONKey = UnknownKeysError
class MissingData(ParseError):
"""
Error raised when unable to create a class instance, as the JSON object
is None.
"""
_TEMPLATE: str
nested_class_name: str
def __init__(self, nested_cls: type, **kwargs):
...
@property
def message(self) -> str: ...
class RecursiveClassError(JSONWizardError):
"""
Error raised when we encounter a `RecursionError` due to cyclic
or self-referential dataclasses.
"""
_TEMPLATE: str
class_name: str
def __init__(self, cls: type): ...
@property
def message(self) -> str: ...
class InvalidConditionError(JSONWizardError):
"""
Error raised when a condition is not wrapped in ``SkipIf``.
"""
_TEMPLATE: str
class_name: str
field_name: str
def __init__(self, cls: type, field_name: str):
...
@property
def message(self) -> str: ...
class MissingVars(JSONWizardError):
"""
Error raised when unable to create an instance of a EnvWizard subclass
(most likely due to missing environment variables in the Environment)
"""
_TEMPLATE: str
class_name: str
fields: str
def_resolution: str
init_resolution: str
prefix: str
def __init__(self,
cls: type,
missing_vars: Sequence[tuple[str, str | None, str, Any]]):
...
@property
def message(self) -> str: ...
|