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

Method from_string_list

traitlets/traitlets.py:4076–4100  ·  view source on GitHub ↗

Return a dict from a list of config strings. This is where we parse CLI configuration. Each item should have the form ``"key=value"``. item parsing is done in :meth:`.item_from_string`.

(self, s_list: list[str])

Source from the content-addressed store, hash-verified

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.
4078
4079 This is where we parse CLI configuration.
4080
4081 Each item should have the form ``"key=value"``.
4082
4083 item parsing is done in :meth:`.item_from_string`.
4084 """
4085 if len(s_list) == 1 and s_list[0] == "None" and self.allow_none:
4086 return None
4087 if len(s_list) == 1 and s_list[0].startswith("{") and s_list[0].endswith("}"):
4088 warn(
4089 f"--{self.name}={s_list[0]} for dict-traits is deprecated in traitlets 5.0. "
4090 f"You can pass --{self.name} <key=value> ... multiple times to add items to a dict.",
4091 DeprecationWarning,
4092 stacklevel=2,
4093 )
4094
4095 return literal_eval(s_list[0])
4096
4097 combined = {}
4098 for d in [self.item_from_string(s) for s in s_list]:
4099 combined.update(d)
4100 return combined
4101
4102 def item_from_string(self, s: str) -> dict[K, V]:
4103 """Cast a single-key dict from a string.

Callers 1

from_stringMethod · 0.95

Calls 3

item_from_stringMethod · 0.95
warnFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected