Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagusiak committed Jun 30, 2024
1 parent 18cd010 commit a75e71f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions alphaconf/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion alphaconf/internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions alphaconf/internal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ def get(
type: Type[T],
*,
default: Union[T, RaiseOnMissingType] = raise_on_missing,
) -> T:
...
) -> T: ...

@overload
def get(
Expand All @@ -65,8 +64,7 @@ def get(
type: Union[str, None] = None,
*,
default: Any = raise_on_missing,
) -> Any:
...
) -> Any: ...

@overload
def get(
Expand All @@ -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"""
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,5 +79,5 @@ ignore = [
"SIM108", # simplify ITE by operator
]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 10
2 changes: 1 addition & 1 deletion tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a75e71f

Please sign in to comment.