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

Method from_string

traitlets/traitlets.py:4064–4074  ·  view source on GitHub ↗

Load value from a single string

(self, s: str)

Source from the content-addressed store, hash-verified

4062 # to opt out of instance_init
4063
4064 def from_string(self, s: str) -> dict[K, V] | None:
4065 """Load value from a single string"""
4066 if not isinstance(s, str):
4067 raise TypeError(f"from_string expects a string, got {s!r} of type {type(s)}")
4068 try:
4069 return self.from_string_list([s]) # type:ignore[no-any-return]
4070 except Exception:
4071 test = _safe_literal_eval(s)
4072 if isinstance(test, dict):
4073 return test
4074 raise
4075
4076 def from_string_list(self, s_list: list[str]) -> t.Any:
4077 """Return a dict from a list of config strings.

Callers

nothing calls this directly

Calls 2

from_string_listMethod · 0.95
_safe_literal_evalFunction · 0.85

Tested by

no test coverage detected