MCPcopy Create free account
hub / github.com/cdgriffith/Box / __init__

Method __init__

box/box.py:374–410  ·  view source on GitHub ↗
(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

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 if isinstance(args[0], str):
387 raise BoxValueError("Cannot extrapolate Box from string")
388 if isinstance(args[0], Mapping):
389 for k, v in args[0].items():
390 if v is args[0]:
391 v = self
392 if v is None and self._box_config["default_box"] and self._box_config["default_box_none_transform"]:
393 continue
394 self.__setitem__(k, v)
395 elif isinstance(args[0], Iterable):
396 for k, v in args[0]:
397 self.__setitem__(k, v)
398 else:
399 raise BoxValueError("First argument must be mapping or iterable")
400 if isinstance(args[0], Box):
401 args[0]._comment_copy_to(self)
402 elif args:
403 raise BoxTypeError(f"Box expected at most 1 argument, got {len(args)}")
404
405 for k, v in kwargs.items():
406 if args and isinstance(args[0], Mapping) and v is args[0]:
407 v = self
408 self.__setitem__(k, v)
409
410 self._box_config["__created"] = True
411
412 def __add__(self, other: Mapping[Any, Any]):
413 if not isinstance(other, dict):

Callers

nothing calls this directly

Calls 7

__setitem__Method · 0.95
BoxErrorClass · 0.90
BoxValueErrorClass · 0.90
BoxTypeErrorClass · 0.90
_build_box_configFunction · 0.85
itemsMethod · 0.45
_comment_copy_toMethod · 0.45

Tested by

no test coverage detected