Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for change in ArgumentParser._parse_known_args since Python 3.12.8 and 3.13.1 #644

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading