pyconfs/configuration.py
def replace(
        self,
        key: str,
        *,
        converter: Optional[Callable[[str], Any]] = None,
        dedent: bool = False,
        default: Optional[str] = None,
        **replace_vars: str,
    ) -> Any:
        """Replace values in an entry based on {} format strings"""
        all_vars = Variables(**self.vars, **replace_vars, default=default)
        value = (
            textwrap.dedent(self.get(key, strict=True))
            if dedent
            else self.get(key, strict=True)
        )

        # Replace variables
        try:
            replaced = value.format_map(all_vars)
        except AttributeError:
            raise _exceptions.ConversionError(
                f"Only strings can be replaced, not {type(value).__name__!r} "
            ) from None

        # Optionally convert value to a different data type
        if converter is None:
            return replaced
        elif callable(converter):
            return converter(replaced)
        else:
            return _converters.convert(f"to_{converter}", value=replaced)
Replace values in an entry based on {} format strings
Replace values in an entry based on {} format strings
Replace values in an entry based on {} format strings
def replace(
        self,
        key: str,
        *,
        converter: Optional[Callable[[str], Any]] = None,
        dedent: bool = False,
        default: Optional[str] = None,
        **replace_vars: str,
    ) -> Any:
        all_vars = Variables(**self.vars, **replace_vars, default=default)
        value = (
            textwrap.dedent(self.get(key, strict=True))
            if dedent
            else self.get(key, strict=True)
        )
        try:
            replaced = value.format_map(all_vars)
        except AttributeError:
            raise _exceptions.ConversionError(
                f"Only strings can be replaced, not {type(value).__name__!r} "
            ) from None
        if converter is None:
            return replaced
        elif callable(converter):
            return converter(replaced)
        else:
            return _converters.convert(f"to_{converter}", value=replaced)
def replace ( self , key : str , * , converter : Optional [ Callable [ [ str ] , Any ] ] = None , dedent : bool = False , default : Optional [ str ] = None , ** replace_vars : str , ) -> Any : all_vars = Variables ( ** self . vars , ** replace_vars , default = default ) value = ( textwrap . dedent ( self . get ( key , strict = True ) ) if dedent else self . get ( key , strict = True ) ) try : replaced = value . format_map ( all_vars ) except AttributeError : raise _exceptions . ConversionError ( f"Only strings can be replaced, not {type(value).__name__!r} " ) from None if converter is None : return replaced elif callable ( converter ) : return converter ( replaced ) else : return _converters . convert ( f"to_{converter}" , value = replaced )
Replace values in an entry based on {} format strings
Replace values in an entry based on {} format strings
"""Replace values in an entry based on {} format strings""" # Replace variables # Optionally convert value to a different data type
self
key
str
converter
Optional[Callable[[str], Any]]
dedent
bool
default
Optional[str]
replace_vars
str