Skip to content

Commit a3fa83a

Browse files
authored
Update pre-commit config (#831)
1 parent 1fedc97 commit a3fa83a

File tree

3 files changed

+47
-88
lines changed

3 files changed

+47
-88
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ ci:
77
skip:
88
- twine-check
99
- changelog-bump
10-
autofix_prs: false
10+
autofix_prs: true
11+
autoupdate_schedule: quarterly
1112

1213
repos:
1314

@@ -24,12 +25,12 @@ repos:
2425
exclude: .bumpversion.cfg
2526

2627
- repo: https://github.com/psf/black
27-
rev: 25.12.0
28+
rev: 26.1.0
2829
hooks:
2930
- id: black
3031

3132
- repo: https://github.com/astral-sh/ruff-pre-commit
32-
rev: v0.14.10
33+
rev: v0.14.13
3334
hooks:
3435
- id: ruff
3536
args: ["--fix"]
@@ -40,7 +41,7 @@ repos:
4041
- id: yesqa
4142

4243
- repo: https://github.com/crate-ci/typos
43-
rev: v1.41.0
44+
rev: v1.42.1
4445
hooks:
4546
- id: typos
4647
args: []

jsonargparse/_deprecated.py

Lines changed: 38 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,10 @@ def patched_save(self, cfg: Union[Namespace, Dict[str, Any]], *args, multifile:
190190
ArgumentParser.save = patched_save
191191

192192

193-
@deprecated(
194-
"""
193+
@deprecated("""
195194
ActionEnum was deprecated in v3.9.0 and will be removed in v5.0.0. Enums now
196195
should be given directly as a type as explained in :ref:`enums`.
197-
"""
198-
)
196+
""")
199197
class ActionEnum:
200198
"""An action based on an Enum that maps to-from strings and enum values."""
201199

@@ -215,12 +213,10 @@ def __call__(self, *args, **kwargs):
215213
return ActionTypeHint(typehint=self._type)(**kwargs)
216214

217215

218-
@deprecated(
219-
"""
216+
@deprecated("""
220217
ActionOperators was deprecated in v3.0.0 and will be removed in v5.0.0. Now
221218
types should be used as explained in :ref:`restricted-numbers`.
222-
"""
223-
)
219+
""")
224220
class ActionOperators:
225221
"""Action to restrict a value with comparison operators."""
226222

@@ -245,12 +241,10 @@ def __call__(self, *args, **kwargs):
245241
return ActionTypeHint(typehint=self._type)(**kwargs)
246242

247243

248-
@deprecated(
249-
"""
244+
@deprecated("""
250245
ActionPath was deprecated in v3.11.0 and will be removed in v5.0.0. Paths
251246
now should be given directly as a type as explained in :ref:`parsing-paths`.
252-
"""
253-
)
247+
""")
254248
class ActionPath:
255249
"""Action to check and store a path."""
256250

@@ -269,12 +263,10 @@ def __call__(self, *args, **kwargs):
269263
return ActionTypeHint(typehint=self._type)(**kwargs)
270264

271265

272-
@deprecated(
273-
"""
266+
@deprecated("""
274267
ActionPathList was deprecated in v4.20.0 and will be removed in v5.0.0. Instead
275268
use as type ``List[<path_type>]`` with ``enable_path=True``.
276-
"""
277-
)
269+
""")
278270
class ActionPathList(Action):
279271
"""Action to check and store a list of file paths read from a plain text file or stream."""
280272

@@ -351,13 +343,11 @@ def _check_type(self, value):
351343
return value
352344

353345

354-
@deprecated(
355-
"""
346+
@deprecated("""
356347
set_url_support was deprecated in v3.12.0 and will be removed in v5.0.0.
357348
Optional config read modes should now be set using function
358349
set_parsing_settings.
359-
"""
360-
)
350+
""")
361351
def set_url_support(enabled: bool):
362352
"""Enables/disables URL support for config read mode."""
363353
from ._optionals import _get_config_read_mode, _set_config_read_mode
@@ -368,13 +358,11 @@ def set_url_support(enabled: bool):
368358
)
369359

370360

371-
@deprecated(
372-
"""
361+
@deprecated("""
373362
set_config_read_mode was deprecated in v4.39.0 and will be removed in
374363
v5.0.0. Optional config read modes should now be set using function
375364
set_parsing_settings.
376-
"""
377-
)
365+
""")
378366
def set_config_read_mode(
379367
urls_enabled: bool = False,
380368
fsspec_enabled: bool = False,
@@ -388,26 +376,22 @@ def set_config_read_mode(
388376
)
389377

390378

391-
@deprecated(
392-
"""
379+
@deprecated("""
393380
get_config_read_mode was deprecated in v4.39.0 and will be removed in
394381
v5.0.0. The config read mode is internal and thus shouldn't be used.
395-
"""
396-
)
382+
""")
397383
def get_config_read_mode() -> str:
398384
"""Returns the current config reading mode."""
399385
from ._optionals import _get_config_read_mode
400386

401387
return _get_config_read_mode()
402388

403389

404-
@deprecated(
405-
"""
390+
@deprecated("""
406391
set_docstring_parse_options was deprecated in v4.39.0 and will be removed in
407392
v5.0.0. Docstring parse options should now be set using function
408393
set_parsing_settings.
409-
"""
410-
)
394+
""")
411395
def set_docstring_parse_options(style=None, attribute_docstrings: Optional[bool] = None):
412396
"""Sets options for docstring parsing."""
413397
from ._optionals import _set_docstring_parse_options
@@ -526,13 +510,11 @@ class DebugException(Exception):
526510
pass
527511

528512

529-
@deprecated(
530-
"""
513+
@deprecated("""
531514
usage_and_exit_error_handler was deprecated in v4.20.0 and will be removed
532515
in v5.0.0. With the removal of error_handler, there is no longer a need for
533516
this function.
534-
"""
535-
)
517+
""")
536518
def usage_and_exit_error_handler(parser: ArgumentParser, message: str) -> None:
537519
"""Prints the usage and exits with error code 2 (same behavior as argparse).
538520
@@ -621,32 +603,26 @@ def default_meta(self, default_meta: bool):
621603
else:
622604
raise ValueError("default_meta expects a boolean.")
623605

624-
@deprecated(
625-
"""
606+
@deprecated("""
626607
instantiate_subclasses was deprecated in v4.0.0 and will be removed in v5.0.0.
627608
Instead use instantiate_classes.
628-
"""
629-
)
609+
""")
630610
def instantiate_subclasses(self, cfg: Namespace) -> Namespace:
631611
return self.instantiate_classes(cfg, instantiate_groups=False) # type: ignore[attr-defined]
632612

633-
@deprecated(
634-
"""
613+
@deprecated("""
635614
add_dataclass_arguments was deprecated in v4.35.0 and will be removed in
636615
v5.0.0. Instead use add_class_arguments.
637-
"""
638-
)
616+
""")
639617
def add_dataclass_arguments(self, *args, **kwargs):
640618
if "title" in kwargs:
641619
kwargs["help"] = kwargs.pop("title")
642620
return self.add_class_arguments(*args, **kwargs)
643621

644-
@deprecated(
645-
"""
622+
@deprecated("""
646623
ArgumentParser.check_config was deprecated in v4.35.0 and will be removed in
647624
v5.0.0. Instead use validate.
648-
"""
649-
)
625+
""")
650626
def check_config(self, *args, **kwargs):
651627
return self.validate(*args, **kwargs)
652628

@@ -691,14 +667,12 @@ def deprecated_module(module_name, mappings=None):
691667
module = ModuleType(module_path, f"deprecated {module_path}")
692668
sys.modules[module_path] = module
693669

694-
@deprecated(
695-
f"""
670+
@deprecated(f"""
696671
Only use the public API as described in
697672
https://jsonargparse.readthedocs.io/en/stable/#api-reference. Importing
698673
from {module_path} is kept only to avoid breaking code that does not
699674
correctly use the public API. It will no longer be available from v5.0.0.
700-
"""
701-
)
675+
""")
702676
def __getattr__(name):
703677
new_module = f"_{module_name}"
704678
if mappings and name in mappings:
@@ -732,12 +706,10 @@ def __getattr__(name):
732706
)
733707

734708

735-
@deprecated(
736-
"""
709+
@deprecated("""
737710
ActionJsonnetExtVars was deprecated in v4.24.0 and will be removed in
738711
v5.0.0. Instead use ``type=dict``.
739-
"""
740-
)
712+
""")
741713
class ActionJsonnetExtVars:
742714
"""Action to add argument to provide ext_vars for jsonnet parsing."""
743715

@@ -749,36 +721,30 @@ def __call__(self, *args, **kwargs):
749721
return action
750722

751723

752-
@deprecated(
753-
"""
724+
@deprecated("""
754725
LoggerProperty was deprecated in v4.40.0 and will be removed from the public
755726
API in v5.0.0. There is no replacement since jsonargparse is not a logging
756727
library. A similar class can be found in reconplogger package.
757-
"""
758-
)
728+
""")
759729
class LoggerProperty(InternalLoggerProperty):
760730
"""Adds a logger property, intended for internal use."""
761731

762732

763-
@deprecated(
764-
"""
733+
@deprecated("""
765734
namespace_to_dict was deprecated in v4.40.0 and will be removed in v5.0.0.
766735
Instead you can use ``.clone().as_dict()`` or ``.as_dict()``.
767-
"""
768-
)
736+
""")
769737
def namespace_to_dict(namespace: Namespace) -> Dict[str, Any]:
770738
"""Returns a copy of a nested namespace converted into a nested dictionary."""
771739
return namespace.clone().as_dict()
772740

773741

774-
@deprecated(
775-
"""
742+
@deprecated("""
776743
dict_to_namespace was deprecated in v4.43.0 and will be removed in v5.0.0.
777744
No replacement is provided because blindly converting a dictionary to a
778745
namespace may not yield the same results as using a parser, which could lead
779746
to confusion.
780-
"""
781-
)
747+
""")
782748
def dict_to_namespace(cfg_dict: dict[str, Any]) -> Namespace:
783749
"""Converts a nested dictionary into a nested namespace."""
784750
from ._namespace import dict_to_namespace as _dict_to_namespace
@@ -794,12 +760,10 @@ def strip_meta(cfg: "Namespace") -> "Namespace": ... # pragma: no cover
794760
def strip_meta(cfg: Dict[str, Any]) -> Dict[str, Any]: ... # pragma: no cover
795761

796762

797-
@deprecated(
798-
"""
763+
@deprecated("""
799764
strip_meta was deprecated in v4.43.0 and will be removed in v5.0.0.
800765
Instead use ``.clone(with_meta=False)``.
801-
"""
802-
)
766+
""")
803767
def strip_meta(cfg):
804768
"""Removes all metadata keys from a configuration object."""
805769
from ._namespace import remove_meta
@@ -856,13 +820,11 @@ def set_yaml_argument_comment(self, text: str, cfg: ruamelCommentedMap, key: str
856820
self._yaml_formatter.set_yaml_argument_comment(text, cfg, key, depth)
857821

858822

859-
@deprecated(
860-
"""
823+
@deprecated("""
861824
compose_dataclasses is deprecated and will be removed in v5.0.0. There is
862825
no direct replacement, whoever is interested can copy the code from an old
863826
release.
864-
"""
865-
)
827+
""")
866828
def compose_dataclasses(*args):
867829
"""Returns a dataclass inheriting all given dataclasses and properly handling __post_init__."""
868830

jsonargparse_tests/test_subclasses.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,8 +1838,7 @@ def __init__(self, val: Optional[Union[int, dict]] = None):
18381838
def test_subclass_error_indentation_invalid_init_arg(parser):
18391839
parser.add_subclass_arguments(ErrorIndentation1, "cls")
18401840
err = get_parse_args_stderr(parser, ["--cls=ErrorIndentation1", "--cls.init_args.val=abc"])
1841-
expected = textwrap.dedent(
1842-
"""
1841+
expected = textwrap.dedent("""
18431842
Parser key "val":
18441843
Does not validate against any of the Union subtypes
18451844
Subtypes: [<class 'NoneType'>, <class 'int'>, <class 'dict'>]
@@ -1849,8 +1848,7 @@ def test_subclass_error_indentation_invalid_init_arg(parser):
18491848
- Expected a <class 'dict'>
18501849
Given value type: <class 'str'>
18511850
Given value: abc
1852-
"""
1853-
).strip()
1851+
""").strip()
18541852
expected = textwrap.indent(expected, " ")
18551853
assert "\n".join(expected.splitlines()) in "\n".join(err.splitlines())
18561854

@@ -1865,8 +1863,7 @@ def test_subclass_error_indentation_in_union_invalid_value(parser):
18651863
parser.add_argument("--cfg", action="config")
18661864
config = {"union": [{"class_path": "ErrorIndentation2", "init_args": {"val": "x"}}]}
18671865
err = get_parse_args_stderr(parser, [f"--cfg={json.dumps(config)}"])
1868-
expected = textwrap.dedent(
1869-
"""
1866+
expected = textwrap.dedent("""
18701867
Errors:
18711868
- Expected a <class 'str'>
18721869
- Not a valid subclass of ErrorIndentation2
@@ -1877,7 +1874,6 @@ def test_subclass_error_indentation_in_union_invalid_value(parser):
18771874
- a dict with parameters accepted by the base class (implicit class_path)
18781875
Given value type: <class 'list'>
18791876
Given value: [{'class_path': 'ErrorIndentation2', 'init_args': {'val': 'x'}}]
1880-
"""
1881-
).strip()
1877+
""").strip()
18821878
expected = textwrap.indent(expected, " ")
18831879
assert "\n".join(expected.splitlines()) in "\n".join(err.splitlines())

0 commit comments

Comments
 (0)