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

Method get_value

traitlets/config/loader.py:439–459  ·  view source on GitHub ↗

Get the value stored in this string

(self, trait: TraitType[t.Any, t.Any])

Source from the content-addressed store, hash-verified

437 """
438
439 def get_value(self, trait: TraitType[t.Any, t.Any]) -> t.Any:
440 """Get the value stored in this string"""
441 if hasattr(trait, "from_string_list"):
442 src = list(self)
443 cast = trait.from_string_list
444 else:
445 # only allow one item
446 if len(self) > 1:
447 raise ValueError(
448 f"{trait.name} only accepts one value, got {len(self)}: {list(self)}"
449 )
450 src = self[0]
451 cast = trait.from_string
452
453 try:
454 return cast(src)
455 except Exception:
456 # exception casting from string,
457 # let the original value lie.
458 # this will raise a more informative error when config is loaded.
459 return src
460
461 def __repr__(self) -> str:
462 return f"{self.__class__.__name__}({self._super_repr()})"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected