(self, *args: Any, **kwargs: Any)
| 372 | return obj |
| 373 | |
| 374 | def __init__(self, *args: Any, **kwargs: Any): |
| 375 | super().__init__() |
| 376 | self._box_config = _build_box_config(self.__class__, kwargs) |
| 377 | if not self._box_config["conversion_box"] and self._box_config["box_duplicates"] != "ignore": |
| 378 | raise BoxError("box_duplicates are only for conversion_boxes") |
| 379 | if ( |
| 380 | self._box_config["camel_killer_box_keep_keys"] |
| 381 | and self._box_config["camel_killer_box"] |
| 382 | and not self._box_config["conversion_box"] |
| 383 | ): |
| 384 | raise BoxError("camel_killer_box_keep_keys needs conversion_box, it provides the snake_case aliases") |
| 385 | if len(args) == 1: |
| 386 | source = args[0] |
| 387 | if isinstance(source, str): |
| 388 | raise BoxValueError("Cannot extrapolate Box from string") |
| 389 | if not isinstance(source, Mapping) and hasattr(source, "keys"): |
| 390 | # Anything with keys() and item access is a mapping to dict() and to Box.update(), a sqlite3.Row |
| 391 | # for one. Read it as one here too, not as an iterable of pairs, which a Row's values are not. |
| 392 | source = {k: source[k] for k in source.keys()} |
| 393 | if isinstance(source, Mapping): |
| 394 | for k, v in source.items(): |
| 395 | if v is args[0]: |
| 396 | v = self |
| 397 | if v is None and self._box_config["default_box"] and self._box_config["default_box_none_transform"]: |
| 398 | continue |
| 399 | self.__setitem__(k, v) |
| 400 | elif isinstance(source, Iterable): |
| 401 | for k, v in source: |
| 402 | self.__setitem__(k, v) |
| 403 | else: |
| 404 | raise BoxValueError("First argument must be mapping or iterable") |
| 405 | if isinstance(args[0], Box): |
| 406 | args[0]._comment_copy_to(self) |
| 407 | elif args: |
| 408 | raise BoxTypeError(f"Box expected at most 1 argument, got {len(args)}") |
| 409 | |
| 410 | for k, v in kwargs.items(): |
| 411 | if args and isinstance(args[0], Mapping) and v is args[0]: |
| 412 | v = self |
| 413 | self.__setitem__(k, v) |
| 414 | |
| 415 | self._box_config["__created"] = True |
| 416 | |
| 417 | def __add__(self, other: Mapping[Any, Any]): |
| 418 | if not isinstance(other, dict): |
nothing calls this directly
no test coverage detected