diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index 238ace6a..0d6919a2 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -9,7 +9,7 @@ on: type: choice options: - windows-2019 - - macOS-12 + - macOS-15 - ubuntu-22.04 jobs: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 31c5ebda..e3d506fe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: - run: tox -e py-all-extras unittest-macos: - runs-on: macOS-12 + runs-on: macOS-15 strategy: fail-fast: false matrix: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 87cae4cf..cfa9a890 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-ast @@ -24,12 +24,12 @@ repos: exclude: .bumpversion.cfg - repo: https://github.com/psf/black - rev: 24.8.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.8 + rev: v0.6.9 hooks: - id: ruff args: ["--fix"] @@ -40,14 +40,14 @@ repos: - id: yesqa - repo: https://github.com/crate-ci/typos - rev: v1.25.0 + rev: v1.26.0 hooks: - id: typos args: [] verbose: true - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.11.2 + rev: v1.12.0 hooks: - id: mypy files: jsonargparse.*/.*.py diff --git a/jsonargparse/_actions.py b/jsonargparse/_actions.py index e2bcadae..938d4946 100644 --- a/jsonargparse/_actions.py +++ b/jsonargparse/_actions.py @@ -13,7 +13,7 @@ from ._loaders_dumpers import get_loader_exceptions, load_value from ._namespace import Namespace, NSKeyError, split_key, split_key_root from ._optionals import get_config_read_mode -from ._type_checking import ArgumentParser +from ._type_checking import ActionsContainer, ArgumentParser from ._util import ( Path, argument_error, @@ -45,7 +45,7 @@ def _is_branch_key(parser, key: str) -> bool: def _find_action_and_subcommand( - parser: "ArgumentParser", + parser: Union["ArgumentParser", "ActionsContainer"], dest: str, exclude: Optional[Union[Type[ArgparseAction], Tuple[Type[ArgparseAction], ...]]] = None, ) -> Tuple[Optional[ArgparseAction], Optional[str]]: @@ -82,7 +82,7 @@ def _find_action_and_subcommand( def _find_action( - parser: "ArgumentParser", + parser: Union["ArgumentParser", "ActionsContainer"], dest: str, exclude: Optional[Union[Type[ArgparseAction], Tuple[Type[ArgparseAction], ...]]] = None, ) -> Optional[ArgparseAction]: diff --git a/jsonargparse/_core.py b/jsonargparse/_core.py index 0f137bc5..063b623f 100644 --- a/jsonargparse/_core.py +++ b/jsonargparse/_core.py @@ -145,7 +145,7 @@ def add_argument(self, *args, enable_path: bool = False, **kwargs): if action.help is None: action.help = empty_help if action.required: - parser.required_args.add(action.dest) + parser.required_args.add(action.dest) # type: ignore[union-attr] action._required = True # type: ignore[attr-defined] action.required = False return action @@ -167,13 +167,13 @@ def add_argument_group(self, *args, name: Optional[str] = None, **kwargs) -> "_A ValueError: If group with the same name already exists. """ parser = self.parser if hasattr(self, "parser") else self - if name is not None and name in parser.groups: + if name is not None and name in parser.groups: # type: ignore[union-attr] raise ValueError(f"Group with name {name} already exists.") group = _ArgumentGroup(parser, *args, logger=parser._logger, **kwargs) group.parser = parser - parser._action_groups.append(group) + parser._action_groups.append(group) # type: ignore[union-attr] if name is not None: - parser.groups[name] = group + parser.groups[name] = group # type: ignore[union-attr] return group @@ -181,7 +181,7 @@ class _ArgumentGroup(ActionsContainer, argparse._ArgumentGroup): """Extension of argparse._ArgumentGroup to support additional functionalities.""" dest: Optional[str] = None - parser: Optional["ArgumentParser"] = None + parser: Optional[Union["ArgumentParser", "ActionsContainer"]] = None class ArgumentParser(ParserDeprecations, ActionsContainer, ArgumentLinking, argparse.ArgumentParser): @@ -1371,10 +1371,10 @@ def _check_value_key(self, action: argparse.Action, value: Any, key: str, cfg: O elif action.type is not None: try: if action.nargs in {None, "?"} or action.nargs == 0: - value = action.type(value) + value = action.type(value) # type: ignore[operator] elif value is not None: for k, v in enumerate(value): - value[k] = action.type(v) + value[k] = action.type(v) # type: ignore[operator] except (TypeError, ValueError) as ex: raise TypeError(f'Parser key "{key}": {ex}') from ex if not is_subcommand and action.choices: diff --git a/jsonargparse/_deprecated.py b/jsonargparse/_deprecated.py index e0c59897..bb3a615c 100644 --- a/jsonargparse/_deprecated.py +++ b/jsonargparse/_deprecated.py @@ -512,7 +512,7 @@ def error_handler(self, error_handler): if error_handler is not False: stacklevel = 2 stack = inspect.stack()[1] - if stack.filename.endswith("jsonargparse/_deprecated.py"): + if stack.filename.endswith(os.fspath(Path("jsonargparse", "_deprecated.py"))): stacklevel = 5 deprecation_warning_error_handler(stacklevel) if callable(error_handler) or error_handler in {None, False}: diff --git a/jsonargparse/_type_checking.py b/jsonargparse/_type_checking.py index 6ceef996..c05342e2 100644 --- a/jsonargparse/_type_checking.py +++ b/jsonargparse/_type_checking.py @@ -2,6 +2,7 @@ __all__ = [ "_ArgumentGroup", + "ActionsContainer", "ArgumentParser", "ruyamlCommentedMap", ] @@ -9,6 +10,6 @@ if TYPE_CHECKING: # pragma: no cover from ruyaml.comments import CommentedMap as ruyamlCommentedMap - from ._core import ArgumentParser, _ArgumentGroup + from ._core import ActionsContainer, ArgumentParser, _ArgumentGroup else: globals().update({k: None for k in __all__})