Skip to content

Commit

Permalink
- Fix path check not platform independent.
Browse files Browse the repository at this point in the history
- Update pre-commit versions.
- Fix mypy errors.
- Update workflows macos labels.
  • Loading branch information
mauvilsa committed Oct 17, 2024
1 parent 3f62519 commit 43ce1ab
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
type: choice
options:
- windows-2019
- macOS-12
- macOS-15
- ubuntu-22.04

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions jsonargparse/_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]]:
Expand Down Expand Up @@ -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]:
Expand Down
14 changes: 7 additions & 7 deletions jsonargparse/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -167,21 +167,21 @@ 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


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):
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion jsonargparse/_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}:
Expand Down
3 changes: 2 additions & 1 deletion jsonargparse/_type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

__all__ = [
"_ArgumentGroup",
"ActionsContainer",
"ArgumentParser",
"ruyamlCommentedMap",
]

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__})

0 comments on commit 43ce1ab

Please sign in to comment.