MCPcopy Create free account
hub / github.com/ipython/traitlets / _DefaultOptionDict

Class _DefaultOptionDict

traitlets/config/loader.py:742–777  ·  view source on GitHub ↗

Like the default options dict but acts as if all --Class.trait options are predefined

Source from the content-addressed store, hash-verified

740
741
742class _DefaultOptionDict(dict): # type:ignore[type-arg]
743 """Like the default options dict
744
745 but acts as if all --Class.trait options are predefined
746 """
747
748 def _add_kv_action(self, key: str) -> None:
749 self[key] = _KVAction(
750 option_strings=[key],
751 dest=key.lstrip("-").replace(".", _DOT_REPLACEMENT),
752 # use metavar for display purposes
753 metavar=key.lstrip("-"),
754 )
755
756 def __contains__(self, key: t.Any) -> bool:
757 if "=" in key:
758 return False
759 if super().__contains__(key):
760 return True
761
762 if key.startswith("-") and class_trait_opt_pattern.match(key):
763 self._add_kv_action(key)
764 return True
765 return False
766
767 def __getitem__(self, key: str) -> t.Any:
768 if key in self:
769 return super().__getitem__(key)
770 else:
771 raise KeyError(key)
772
773 def get(self, key: str, default: t.Any = None) -> t.Any:
774 try:
775 return self[key]
776 except KeyError:
777 return default
778
779
780class _KVArgParser(argparse.ArgumentParser):

Callers 1

parse_known_argsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…