Return the value from a list of config strings This is where we parse CLI configuration
(self, s_list: list[str])
| 3534 | return self.validate(None, test) |
| 3535 | |
| 3536 | def from_string_list(self, s_list: list[str]) -> T | None: |
| 3537 | """Return the value from a list of config strings |
| 3538 | |
| 3539 | This is where we parse CLI configuration |
| 3540 | """ |
| 3541 | assert self.klass is not None |
| 3542 | if len(s_list) == 1: |
| 3543 | # check for deprecated --Class.trait="['a', 'b', 'c']" |
| 3544 | r = s_list[0] |
| 3545 | if r == "None" and self.allow_none: |
| 3546 | return None |
| 3547 | if len(r) >= 2 and any( |
| 3548 | r.startswith(start) and r.endswith(end) |
| 3549 | for start, end in self._literal_from_string_pairs |
| 3550 | ): |
| 3551 | if self.this_class: |
| 3552 | clsname = self.this_class.__name__ + "." |
| 3553 | else: |
| 3554 | clsname = "" |
| 3555 | assert self.name is not None |
| 3556 | warn( |
| 3557 | "--{0}={1} for containers is deprecated in traitlets 5.0. " |
| 3558 | "You can pass `--{0} item` ... multiple times to add items to a list.".format( |
| 3559 | clsname + self.name, r |
| 3560 | ), |
| 3561 | DeprecationWarning, |
| 3562 | stacklevel=2, |
| 3563 | ) |
| 3564 | return self.klass(literal_eval(r)) # type:ignore[call-arg] |
| 3565 | sig = inspect.signature(self.item_from_string) |
| 3566 | if "index" in sig.parameters: |
| 3567 | item_from_string = self.item_from_string |
| 3568 | else: |
| 3569 | # backward-compat: allow item_from_string to ignore index arg |
| 3570 | def item_from_string(s: str, index: int | None = None) -> T | str: |
| 3571 | return self.item_from_string(s) |
| 3572 | |
| 3573 | return self.klass( # type:ignore[call-arg] |
| 3574 | [item_from_string(s, index=idx) for idx, s in enumerate(s_list)] |
| 3575 | ) |
| 3576 | |
| 3577 | def item_from_string(self, s: str, index: int | None = None) -> T | str: |
| 3578 | """Cast a single item from a string |