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

Method __sub__

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

Source from the content-addressed store, hash-verified

472 return self
473
474 def __sub__(self, other: Mapping[Any, Any]):
475 frozen = self._box_config["frozen_box"]
476 config = self.__box_config()
477 config["frozen_box"] = False
478 config.pop("box_namespace") # Detach namespace; it will be reassigned if we nest again
479 output = self._box_config["box_class"](**config)
480 if not isinstance(other, dict):
481 raise BoxError("Box can only compare two boxes or a box and a dictionary.")
482 if not isinstance(other, Box):
483 other = self._box_config["box_class"](other, **config)
484 for item in self:
485 if item not in other:
486 output[item] = self[item]
487 elif isinstance(self.get(item), Box) and isinstance(other.get(item), Box):
488 output[item] = self[item] - other[item]
489 if not output[item]:
490 del output[item]
491 output._box_config["frozen_box"] = frozen
492 return output
493
494 def __hash__(self):
495 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