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

Fix issue #590: Behavior change in argparse._parse_optional breaks the parse of optional arguments #591

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

eggry
Copy link
Contributor

@eggry eggry commented Oct 5, 2024

What does this PR do?

In Python 3.13 and 3.12.7, the behavior of _parse_optional has changed to return a list of tuples: python/cpython#124631
This change would break the argument parser of this library.
For example, the existing unit test failed, resulting in:

FAILED jsonargparse_tests/test_dataclass_like.py::test_optional_dataclass_single_param_change - argparse.ArgumentError: cannot unpack non-iterable ActionTypeHint object

This PR will detect this behavior and return the proper format accordingly.
This PR resolves issue #590.

Before submitting

  • Did you read the contributing guideline?
  • [n/a] Did you update the documentation? (readme and public docstrings)
  • [n/a] Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

Copy link
Member

@mauvilsa mauvilsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the fix!

Please add at the top of the changelog an entry for this fix, in a new section, like:

v4.33.2 (2024-10-??)
--------------------

Fixed
^^^^^
- ...

Also, since this breaking change also affects argcomplete and we don't know when there will be a new release with the fix, please add to test_argcomplete.py the following:

@pytest.fixture(autouse=True)
def temporal_skip_if_py312():
    if sys.version_info[:2] == (3, 12):
        pytest.skip("currently failing on 3.12 due to argparse breaking change")

Copy link

sonarcloud bot commented Oct 6, 2024

@eggry eggry requested a review from mauvilsa October 6, 2024 07:31
Copy link

codecov bot commented Oct 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a8b8b15) to head (b706c1e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #591   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         6451      6453    +2     
=========================================
+ Hits          6451      6453    +2     
Flag Coverage Δ
py3.10 85.91% <50.00%> (-0.02%) ⬇️
py3.10_all 98.83% <50.00%> (-0.02%) ⬇️
py3.10_pydantic1 49.15% <50.00%> (+<0.01%) ⬆️
py3.10_pydantic2 48.93% <50.00%> (+<0.01%) ⬆️
py3.10_types 98.85% <50.00%> (-0.02%) ⬇️
py3.11 85.88% <0.00%> (-0.03%) ⬇️
py3.11_all 98.79% <0.00%> (-0.04%) ⬇️
py3.11_types 98.80% <0.00%> (-0.04%) ⬇️
py3.12 86.03% <100.00%> (-0.02%) ⬇️
py3.12_all 97.86% <100.00%> (-0.97%) ⬇️
py3.12_types 97.87% <100.00%> (-0.97%) ⬇️
py3.8 86.54% <50.00%> (-0.02%) ⬇️
py3.8_all 99.47% <50.00%> (-0.02%) ⬇️
py3.8_types 99.50% <50.00%> (-0.02%) ⬇️
py3.9 86.46% <50.00%> (-0.02%) ⬇️
py3.9_all 99.42% <50.00%> (-0.02%) ⬇️
py3.9_types 99.44% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mauvilsa mauvilsa added the bug Something isn't working label Oct 7, 2024
@mauvilsa mauvilsa merged commit a209e1e into omni-us:main Oct 7, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants