MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / pop

Method pop

python/bplustree/bplus_tree.py:522–545  ·  view source on GitHub ↗

Remove and return value for key with optional default (dict-like API). Args: key: The key to remove. *args: Optional default value if key is not found. Returns: The value that was associated with key, or default if key not found. Raises:

(self, key: Any, *args)

Source from the content-addressed store, hash-verified

520 self._rightmost_leaf_cache = None
521
522 def pop(self, key: Any, *args) -> Any:
523 """Remove and return value for key with optional default (dict-like API).
524
525 Args:
526 key: The key to remove.
527 *args: Optional default value if key is not found.
528
529 Returns:
530 The value that was associated with key, or default if key not found.
531
532 Raises:
533 KeyError: If key is not found and no default is provided.
534 """
535 if len(args) > 1:
536 raise TypeError(f"pop expected at most 2 arguments, got {len(args) + 1}")
537
538 try:
539 value = self[key]
540 del self[key]
541 return value
542 except KeyError:
543 if args:
544 return args[0]
545 raise
546
547 def popitem(self) -> Tuple[Any, Any]:
548 """Remove and return an arbitrary (key, value) pair (dict-like API).

Callers 6

_merge_with_siblingMethod · 0.45
borrow_from_leftMethod · 0.45
borrow_from_rightMethod · 0.45
deleteMethod · 0.45
borrow_from_leftMethod · 0.45
borrow_from_rightMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected