Skip to content

Commit

Permalink
Merge pull request #61 from edornd/bugfix/59-cli-override
Browse files Browse the repository at this point in the history
Fix order in static sources (#59)
  • Loading branch information
edornd authored Jan 10, 2025
2 parents b5a2e2d + 4e18ace commit 33f65c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.6
rev: v0.9.0
hooks:
# Run the linter.
- id: ruff
Expand Down
27 changes: 14 additions & 13 deletions argdantic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ def __init__(
self.commands: List[Command] = []
self.groups: List[ParserType] = []
# internal variables
assert (
internal_delimiter.isidentifier()
), f"The internal delimiter {internal_delimiter} is not a valid identifier"
assert internal_delimiter.isidentifier(), (
f"The internal delimiter {internal_delimiter} is not a valid identifier"
)

self._delimiter = delimiter
self._internal_delimiter = internal_delimiter
self._subcommand_meta = subcommand_meta
Expand Down Expand Up @@ -267,20 +268,20 @@ def decorator(f: Callable) -> Command:
# if the function expects a single argument, we do not wrap it
# otherwise, we prepare the fields for the wrapper model
if singleton:
assert (
len(func_params) == 1
), f"The command '{command_name}' expects a single argument, but {len(func_params)} were provided"
assert len(func_params) == 1, (
f"The command '{command_name}' expects a single argument, but {len(func_params)} were provided"
)
param_name, param = func_params[0]
assert lenient_issubclass(
param.annotation, BaseModel
), f"The singleton argument '{param_name}' must be a pydantic model"
assert lenient_issubclass(param.annotation, BaseModel), (
f"The singleton argument '{param_name}' must be a pydantic model"
)
model_class = param.annotation

else:
for param_name, param in func_params:
assert (
param.annotation is not inspect.Parameter.empty
), f"Field '{param_name}' lacks type annotations"
assert param.annotation is not inspect.Parameter.empty, (
f"Field '{param_name}' lacks type annotations"
)
default_value = param.default if param.default is not inspect.Parameter.empty else Ellipsis
wrapped_fields[param_name] = (param.annotation, default_value)

Expand All @@ -306,7 +307,7 @@ def settings_customise_sources(
# Env and file sources are discarded, the user must provide them explicitly.
source_list = cast(List[SettingSourceCallable], sources)
callables = [source(settings_cls) for source in source_list]
return (*callables, init_settings)
return (init_settings, *callables)

model_class = StaticSourceSettings if model_class is None else (model_class, StaticSourceSettings)

Expand Down

0 comments on commit 33f65c4

Please sign in to comment.