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

Class DeferredConfigList

traitlets/config/loader.py:423–462  ·  view source on GitHub ↗

Config value for loading config from a list of strings Interpretation is deferred until it is loaded into the trait. This class is only used for values that are not listed in the configurable classes. When config is loaded, `trait.from_string_list` will be used. If an error i

Source from the content-addressed store, hash-verified

421
422
423class DeferredConfigList(t.List[t.Any], DeferredConfig):
424 """Config value for loading config from a list of strings
425
426 Interpretation is deferred until it is loaded into the trait.
427
428 This class is only used for values that are not listed
429 in the configurable classes.
430
431 When config is loaded, `trait.from_string_list` will be used.
432
433 If an error is raised in `.from_string_list`,
434 the original string list is returned.
435
436 .. versionadded:: 5.0
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()})"
463
464
465# -----------------------------------------------------------------------------

Callers 2

__call__Method · 0.85
_convert_to_configMethod · 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…