diff --git a/alphaconf/inject.py b/alphaconf/inject.py index 7c8e93d..26de30d 100644 --- a/alphaconf/inject.py +++ b/alphaconf/inject.py @@ -52,8 +52,8 @@ def getter( ktype = next(type_from_annotation(ptype), None) if param is not None and param.default is not param.empty: xparam = param - return ( - lambda: xparam.default + return lambda: ( + xparam.default if (value := alphaconf.get(key, ktype, default=None)) is None and xparam.default is not xparam.empty else value diff --git a/alphaconf/internal/arg_parser.py b/alphaconf/internal/arg_parser.py index d993995..3fe0554 100644 --- a/alphaconf/internal/arg_parser.py +++ b/alphaconf/internal/arg_parser.py @@ -91,7 +91,7 @@ class ConfigurationAction(Action): def check_argument(self, value): if self.metavar and '=' in self.metavar and '=' not in value: - return 'Argument should be in format %s' % self.metavar + return f'Argument should be in format {self.metavar}' return super().check_argument(value) def handle(self, result, value): diff --git a/alphaconf/internal/configuration.py b/alphaconf/internal/configuration.py index dbe4b7a..3133f96 100644 --- a/alphaconf/internal/configuration.py +++ b/alphaconf/internal/configuration.py @@ -55,8 +55,7 @@ def get( type: Type[T], *, default: Union[T, RaiseOnMissingType] = raise_on_missing, - ) -> T: - ... + ) -> T: ... @overload def get( @@ -65,8 +64,7 @@ def get( type: Union[str, None] = None, *, default: Any = raise_on_missing, - ) -> Any: - ... + ) -> Any: ... @overload def get( @@ -75,8 +73,7 @@ def get( type: None = None, *, default: Union[T, RaiseOnMissingType] = raise_on_missing, - ) -> T: - ... + ) -> T: ... def get(self, key: Union[str, Type], type=None, *, default=raise_on_missing): """Get a configuation value and cast to the correct type""" diff --git a/pyproject.toml b/pyproject.toml index 5bf437d..5459576 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,6 +54,8 @@ local_scheme = "no-local-version" [tool.ruff] line-length = 100 + +[tool.ruff.lint] # https://beta.ruff.rs/docs/rules/ select = [ #"C9", # mccabe @@ -77,5 +79,5 @@ ignore = [ "SIM108", # simplify ITE by operator ] -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] max-complexity = 10 diff --git a/tests/test_logging.py b/tests/test_logging.py index ddddf8b..9538031 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -40,7 +40,7 @@ def test_log_exception(log, caplog): log.error('err', exc_info=True) rec = caplog.records[0] exc_type, exc, tb = rec.exc_info - assert exc_type == ValueError and str(exc) == 'tvalue' and tb + assert exc_type is ValueError and str(exc) == 'tvalue' and tb def test_log_format(log, caplog):