Esempio n. 1
0
    def validator(config: dict) -> dict:
        """Check if key is in config and log warning."""
        if key in config:
            try:
                KeywordStyleAdapter(logging.getLogger(module_name)).warning(
                    warning.replace(
                        "'{key}' option",
                        f"'{key}' option near {config.__config_file__}:{config.__line__}",  # type: ignore
                    ),
                    key=key,
                    replacement_key=replacement_key,
                )
            except AttributeError:
                KeywordStyleAdapter(logging.getLogger(module_name)).warning(
                    warning,
                    key=key,
                    replacement_key=replacement_key,
                )
            value = config[key]
            if replacement_key:
                config.pop(key)
        else:
            value = default

        keys = [key]
        if replacement_key:
            keys.append(replacement_key)
            if value is not None and (replacement_key not in config or default
                                      == config.get(replacement_key)):
                config[replacement_key] = value

        return has_at_most_one_key(*keys)(config)
Esempio n. 2
0
    def validator(config: Dict) -> Dict:
        """Check if key is in config and log warning."""
        if key in config:
            check_for_invalid_version()
            KeywordStyleAdapter(logging.getLogger(module_name)).warning(
                warning,
                key=key,
                replacement_key=replacement_key,
                invalidation_status="will become",
                invalidation_version=invalidation_version,
            )

            value = config[key]
            if replacement_key:
                config.pop(key)
        else:
            value = default

        keys = [key]
        if replacement_key:
            keys.append(replacement_key)
            if value is not None and (replacement_key not in config or default
                                      == config.get(replacement_key)):
                config[replacement_key] = value

        return has_at_most_one_key(*keys)(config)
Esempio n. 3
0
    def validator(config: Dict):
        """Check if key is in config and log warning."""
        if key in config:
            value = config[key]
            check_for_invalid_version(value)
            KeywordStyleAdapter(logging.getLogger(module_name)).warning(
                warning,
                key=key,
                value=value,
                replacement_key=replacement_key,
                invalidation_version=invalidation_version)
            if replacement_key:
                config.pop(key)
        else:
            value = default
        if (replacement_key and (replacement_key not in config
                                 or default == config.get(replacement_key))
                and value is not None):
            config[replacement_key] = value

        return has_at_most_one_key(key, replacement_key)(config)