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

Method __sub__

box/box.py:465–483  ·  view source on GitHub ↗
(self, other: Mapping[Any, Any])

Source from the content-addressed store, hash-verified

463 return self
464
465 def __sub__(self, other: Mapping[Any, Any]):
466 frozen = self._box_config["frozen_box"]
467 config = self.__box_config()
468 config["frozen_box"] = False
469 config.pop("box_namespace") # Detach namespace; it will be reassigned if we nest again
470 output = self._box_config["box_class"](**config)
471 if not isinstance(other, dict):
472 raise BoxError("Box can only compare two boxes or a box and a dictionary.")
473 if not isinstance(other, Box):
474 other = self._box_config["box_class"](other, **config)
475 for item in self:
476 if item not in other:
477 output[item] = self[item]
478 elif isinstance(self.get(item), Box) and isinstance(other.get(item), Box):
479 output[item] = self[item] - other[item]
480 if not output[item]:
481 del output[item]
482 output._box_config["frozen_box"] = frozen
483 return output
484
485 def __hash__(self):
486 if self._box_config["frozen_box"]:

Callers

nothing calls this directly

Calls 4

__box_configMethod · 0.95
getMethod · 0.95
BoxErrorClass · 0.90
popMethod · 0.45

Tested by

no test coverage detected