Skip to content

Commit edba416

Browse files
authored
Some misc fixes (#891)
1 parent 0b35ad0 commit edba416

File tree

7 files changed

+12
-28
lines changed

7 files changed

+12
-28
lines changed

jsonargparse/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from ._link_arguments import * # noqa: F403
2323
from ._loaders_dumpers import * # noqa: F403
2424
from ._namespace import * # noqa: F403
25-
from ._optionals import * # noqa: F403
2625
from ._paths import Path # noqa: F401
2726
from ._signatures import * # noqa: F403
2827
from ._subcommands import * # noqa: F403
@@ -53,7 +52,6 @@
5352
_link_arguments,
5453
_loaders_dumpers,
5554
_namespace,
56-
_optionals,
5755
_signatures,
5856
_subcommands,
5957
_util,
@@ -70,7 +68,6 @@
7068
__all__ += _actions.__all__
7169
__all__ += _namespace.__all__
7270
__all__ += _formatters.__all__
73-
__all__ += _optionals.__all__
7471
__all__ += _common.__all__
7572
__all__ += _loaders_dumpers.__all__
7673
__all__ += _util.__all__

jsonargparse/_actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
__all__ = [
2929
"ActionFail",
30-
"ActionParser",
3130
"ActionYesNo",
31+
"ActionParser",
3232
]
3333

3434

jsonargparse/_cli.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
from ._optionals import get_doc_short_description
1111
from ._util import capture_parser, default_config_option_help
1212

13-
__all__ = [
14-
"auto_cli",
15-
"auto_parser",
16-
]
13+
__all__ = ["auto_cli", "auto_parser"]
1714

1815

1916
ComponentType = Union[Callable, type]

jsonargparse/_core.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ def __init__(
243243
*args,
244244
env_prefix: Union[bool, str] = True,
245245
formatter_class: type[argparse.HelpFormatter] = DefaultHelpFormatter,
246-
exit_on_error: bool = True,
247246
logger: Union[logging.Logger, bool, str, dict] = False,
248247
version: Optional[str] = None,
249248
print_config: Optional[str] = "--print_config",
@@ -274,7 +273,6 @@ def __init__(
274273
self._group_class = get_argument_group_class(self)
275274
if self.groups is None:
276275
self.groups = {}
277-
self.exit_on_error = exit_on_error
278276
self._extra_required_keys: set[str] = set()
279277
self.save_path_content: set[str] = set()
280278
self.default_config_files = default_config_files
@@ -431,7 +429,7 @@ def parse_args( # type: ignore[override]
431429
A config object with all parsed values.
432430
433431
Raises:
434-
ArgumentError: If the parsing fails and ``exit_on_error=True``.
432+
ArgumentError: If the parsing fails and ``exit_on_error=False``.
435433
"""
436434
skip_validation, namespace_as_config = get_private_kwargs(
437435
kwargs, _skip_validation=False, _namespace_as_config=False
@@ -498,7 +496,7 @@ def parse_object(
498496
A config object with all parsed values.
499497
500498
Raises:
501-
ArgumentError: If the parsing fails and ``exit_on_error=True``.
499+
ArgumentError: If the parsing fails and ``exit_on_error=False``.
502500
"""
503501
skip_validation, skip_required = get_private_kwargs(kwargs, _skip_validation=False, _skip_required=False)
504502

@@ -581,7 +579,7 @@ def parse_env(
581579
A config object with all parsed values.
582580
583581
Raises:
584-
ArgumentError: If the parsing fails and ``exit_on_error=True``.
582+
ArgumentError: If the parsing fails and ``exit_on_error=False``.
585583
"""
586584
skip_validation, skip_subcommands = get_private_kwargs(kwargs, _skip_validation=False, _skip_subcommands=False)
587585

@@ -625,7 +623,7 @@ def parse_path(
625623
A config object with all parsed values.
626624
627625
Raises:
628-
ArgumentError: If the parsing fails and ``exit_on_error=True``.
626+
ArgumentError: If the parsing fails and ``exit_on_error=False``.
629627
"""
630628
fpath = Path(cfg_path, mode=_get_config_read_mode())
631629
with change_to_path_dir(fpath):
@@ -664,7 +662,7 @@ def parse_string(
664662
A config object with all parsed values.
665663
666664
Raises:
667-
ArgumentError: If the parsing fails and ``exit_on_error=True``.
665+
ArgumentError: If the parsing fails and ``exit_on_error=False``.
668666
"""
669667
skip_validation, fail_no_subcommand = get_private_kwargs(
670668
kwargs, _skip_validation=False, _fail_no_subcommand=True

jsonargparse/_optionals.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
from importlib.util import find_spec
1212
from typing import Any, Optional, Union
1313

14-
__all__ = [
15-
"_get_config_read_mode",
16-
]
17-
18-
1914
pyyaml_available = bool(find_spec("yaml"))
2015
toml_load_available = bool(find_spec("toml") or find_spec("tomllib"))
2116
toml_dump_available = bool(find_spec("toml"))

jsonargparse/_postponed_annotations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def _collect_string_fwd_ref_names(typehint: Any, result: set[str]) -> None:
233233

234234

235235
def _update_missing_from_module_vars(global_vars: dict, missing: set[str], mod_vars: dict[str, Any]) -> None:
236-
for name in list(missing):
236+
for name in missing.copy():
237237
if name in mod_vars:
238238
global_vars[name] = mod_vars[name]
239239
missing.discard(name)
@@ -284,7 +284,7 @@ def _enrich_globals_for_string_forward_refs(global_vars: dict[str, Any]) -> None
284284

285285
# Find candidate modules: those that define the same trigger values (by identity).
286286
# This lets us trace generic aliases back to their origin module.
287-
for module_name, mod in list(sys.modules.items()):
287+
for mod in sys.modules.values():
288288
if mod is None or not missing:
289289
continue
290290
try:

jsonargparse/_signatures.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,13 @@ def _add_signature_parameter(
345345
if kind == kinds.POSITIONAL_ONLY:
346346
is_required = True # Always required
347347
is_non_positional = False # Can be positional
348-
elif kind == kinds.POSITIONAL_OR_KEYWORD:
349-
is_required = default == inspect_empty # Required if no default
350-
is_non_positional = False # Can be positional
351348
elif kind == kinds.KEYWORD_ONLY:
352349
is_required = default == inspect_empty # Required if no default
353350
is_non_positional = True # Must use --flag style
354-
elif kind is None:
355-
# programmatically created parameters without kind
351+
elif kind in {kinds.POSITIONAL_OR_KEYWORD, None}:
352+
# POSITIONAL_OR_KEYWORD or programmatically created parameters without kind
356353
is_required = default == inspect_empty # Required if no default
357-
is_non_positional = False # Can be positional (preserve old behavior)
354+
is_non_positional = False # Can be positional
358355
else:
359356
raise RuntimeError(f"The code should never reach here: kind={kind}") # pragma: no cover
360357
src = get_parameter_origins(param.component, param.parent)

0 commit comments

Comments
 (0)