Skip to content

Commit

Permalink
Account for change in ArgumentParser._parse_known_args since Python 3…
Browse files Browse the repository at this point in the history
….12.8 and 3.13.1 (#644)
  • Loading branch information
mauvilsa authored Dec 16, 2024
1 parent a2b4e3d commit da05c1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Changed
the help of the base class is printed (`#628
<https://github.com/omni-us/jsonargparse/pull/628>`__).

Fixed
^^^^^
- Account for change in ``ArgumentParser._parse_known_args`` since Python 3.12.8
and 3.13.1 (`#644 <https://github.com/omni-us/jsonargparse/pull/644>`__).

Deprecated
^^^^^^^^^^
- ``add_dataclass_arguments`` is deprecated and will be removed in v5.0.0.
Expand Down
8 changes: 7 additions & 1 deletion jsonargparse/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
__all__ = ["ActionsContainer", "ArgumentParser"]


_parse_known_has_intermixed = "intermixed" in inspect.signature(argparse.ArgumentParser._parse_known_args).parameters


class ActionsContainer(SignatureArguments, argparse._ActionsContainer):
"""Extension of argparse._ActionsContainer to support additional functionalities."""

Expand Down Expand Up @@ -288,7 +291,10 @@ def parse_known_args(self, args=None, namespace=None):
with patch_namespace(), parser_context(
parent_parser=self, lenient_check=True
), ActionTypeHint.subclass_arg_context(self):
namespace, args = self._parse_known_args(args, namespace)
kwargs = {}
if _parse_known_has_intermixed:
kwargs["intermixed"] = False
namespace, args = self._parse_known_args(args, namespace, **kwargs)
except argparse.ArgumentError as ex:
self.error(str(ex), ex)

Expand Down

0 comments on commit da05c1b

Please sign in to comment.