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

Method __sub__

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

Source from the content-addressed store, hash-verified

360 return self
361
362 def __sub__(self, other: Mapping[Any, Any]):
363 frozen = self._box_config["frozen_box"]
364 config = self.__box_config()
365 config["frozen_box"] = False
366 config.pop("box_namespace") # Detach namespace; it will be reassigned if we nest again
367 output = self._box_config["box_class"](**config)
368 if not isinstance(other, dict):
369 raise BoxError("Box can only compare two boxes or a box and a dictionary.")
370 if not isinstance(other, Box):
371 other = self._box_config["box_class"](other, **config)
372 for item in self:
373 if item not in other:
374 output[item] = self[item]
375 elif isinstance(self.get(item), Box) and isinstance(other.get(item), Box):
376 output[item] = self[item] - other[item]
377 if not output[item]:
378 del output[item]
379 output._box_config["frozen_box"] = frozen
380 return output
381
382 def __hash__(self):
383 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.80

Tested by

no test coverage detected