Skip to content
Snippets Groups Projects
Unverified Commit df4f33c3 authored by Jon Crall's avatar Jon Crall
Browse files

fix: for changes in CPython #125355

parent 3f4271ce
No related branches found
No related tags found
1 merge request!36Start branch for dev/0.8.2
Pipeline #430181 passed
......@@ -18,6 +18,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
* The `smartcast` `allow_split` now works, and defaults to "auto", which will prepare us for a backwards incompatible change to remove the auto string split behavior.
### Fixed
* Fix issue with internal argparse change in CPython#125355
### Added
* Add experimental new method `DataConfig.cls_from_argparse` which dynamically
......
......@@ -36,6 +36,16 @@ HAS_ARGPARSE_GH_114180 = (
(sys.version_info[0:3] >= (3, 12, 3))
)
# NOTE: CPython broke us here by changing the internal API to require an intermixed arg
# https://github.com/python/cpython/issues/125355
# https://github.com/python/cpython/commit/759a54d28ffe7eac8c23917f5d3dfad8309856be#diff-205ef24c9374465bf35c359abce9211d3aa113e986a1e3d41569eb29d07df479
# TODO: we should likely add better support for it, for now we workaround.
HAS_ARGPARSE_GH_125355 = (
(sys.version_info[0:2] == (3, 12) and sys.version_info[2] >= 8) or
(sys.version_info[0:3] >= (3, 13, 1))
)
# Inherit from StoreAction to make configargparse happy. Hopefully python
# doesn't change the behavior of this private class.
# If we ditch support for configargparse in the future, then we can more
......@@ -379,12 +389,18 @@ class CompatArgumentParser(argparse.ArgumentParser):
# parse the arguments and exit if there are any errors
if self.exit_on_error:
try:
namespace, args = self._parse_known_args(args, namespace)
if HAS_ARGPARSE_GH_125355:
namespace, args = self._parse_known_args(args, namespace, intermixed=False)
else:
namespace, args = self._parse_known_args(args, namespace)
except ArgumentError:
err = _sys.exc_info()[1]
self.error(str(err))
else:
namespace, args = self._parse_known_args(args, namespace)
if HAS_ARGPARSE_GH_125355:
namespace, args = self._parse_known_args(args, namespace, intermixed=False)
else:
namespace, args = self._parse_known_args(args, namespace)
if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment