MCPcopy Index your code
hub / github.com/python/cpython / convert

Method convert

Lib/logging/config.py:452–478  ·  view source on GitHub ↗

Convert values to an appropriate type. dicts, lists and tuples are replaced by their converting alternatives. Strings are checked to see if they have a conversion format and are converted if they do.

(self, value)

Source from the content-addressed store, hash-verified

450 return d
451
452 def convert(self, value):
453 """
454 Convert values to an appropriate type. dicts, lists and tuples are
455 replaced by their converting alternatives. Strings are checked to
456 see if they have a conversion format and are converted if they do.
457 """
458 if not isinstance(value, ConvertingDict) and isinstance(value, dict):
459 value = ConvertingDict(value)
460 value.configurator = self
461 elif not isinstance(value, ConvertingList) and isinstance(value, list):
462 value = ConvertingList(value)
463 value.configurator = self
464 elif not isinstance(value, ConvertingTuple) and\
465 isinstance(value, tuple) and not hasattr(value, '_fields'):
466 value = ConvertingTuple(value)
467 value.configurator = self
468 elif isinstance(value, str): # str for py3k
469 m = self.CONVERT_PATTERN.match(value)
470 if m:
471 d = m.groupdict()
472 prefix = d['prefix']
473 converter = self.value_converters.get(prefix, None)
474 if converter:
475 suffix = d['suffix']
476 converter = getattr(self, converter)
477 value = converter(suffix)
478 return value
479
480 def configure_custom(self, config):
481 """Configure an object with a user-supplied factory."""

Callers 1

test_baseconfigMethod · 0.95

Calls 5

ConvertingDictClass · 0.85
ConvertingListClass · 0.85
ConvertingTupleClass · 0.85
matchMethod · 0.45
getMethod · 0.45

Tested by 1

test_baseconfigMethod · 0.76