Skip to content

gh-144782: Make sure that ArgumentParser instances are pickleable#144783

Open
mauvilsa wants to merge 5 commits intopython:mainfrom
mauvilsa:argparse-pickleable
Open

gh-144782: Make sure that ArgumentParser instances are pickleable#144783
mauvilsa wants to merge 5 commits intopython:mainfrom
mauvilsa:argparse-pickleable

Conversation

@mauvilsa
Copy link

@mauvilsa mauvilsa commented Feb 13, 2026

Changes so that argparse.ArgumentParser instances are pickleable and a unit test so that this behavior is preserved.

Fixes issue #144782

@python-cla-bot
Copy link

python-cla-bot bot commented Feb 13, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
@mauvilsa mauvilsa marked this pull request as ready for review February 13, 2026 14:03
@mauvilsa
Copy link
Author

Recent changes in 3.14.3 is making jsonargparse tests fail, see actions/runs/21987177775. Would be good to backport this to 3.14, otherwise pytorch-lightning multiprocessing will be broken on 3.14.

From what I understood in the docs this pull request should have a needs backport to 3.14 label?

@mauvilsa mauvilsa requested a review from johnslavik February 13, 2026 14:32
…Y8TKj.rst

Co-authored-by: AN Long <aisk@users.noreply.github.com>
@mauvilsa mauvilsa requested a review from aisk February 13, 2026 21:37
Copy link
Member

@johnslavik johnslavik left a comment

Choose a reason for hiding this comment

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

Sorry for the review ping-pong, I've had a few new thoughts/suggestions in this round. I don't think there's anything else that will come out on my side. Nice work!

self.assertEqual(ns.bar, 'quux')
ns2 = parser2.parse_args([])
self.assertEqual(ns2.foo, 42)
self.assertEqual(ns2.bar, 'baz')
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to test all pickle protocols, as in test_uuid.BaseTestUUID.test_pickle_roundtrip? cc @savannahostrowski @serhiy-storchaka

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I can do that. Should I wait for a response from @savannahostrowski @serhiy-storchaka?

Copy link
Member

@johnslavik johnslavik Feb 14, 2026

Choose a reason for hiding this comment

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

I think you don't need to wait, @mauvilsa. I've checked this more carefully now and there are lots and lots of precedents that test all protocols:

  • test_array.BaseTest.test_pickle (+related)
  • test_bool.BoolTest.test_pickle
  • test_collections.TestChainMap.test_basics
  • all test_configparser.ExceptionPicklingTestCase test methods
  • test_decimal.ContextAPItests.test_pickle
  • test_functools.TestPartial.test_recursive_pickle
  • much more!

Every roundtrip pickling test I'm looking at covers multiple protocols. I'd say go ahead, it might actually be a requirement we want to uphold in every pickling test :-)

@johnslavik
Copy link
Member

johnslavik commented Feb 13, 2026

From what I understood in the docs this pull request should have a needs backport to 3.14 label?

Bug fixes are backported, yes (to 3.13 as well at the time of writing). The labels can be applied at any point, even after merge. I'm leaving the decision whether we backport this or not to @savannahostrowski -- I'm not sure if this is a bug fix and not a feature, but it seems very reasonable to backport it, so you have a +1 from me in any case!

mauvilsa and others added 2 commits February 14, 2026 07:49
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
@mauvilsa mauvilsa requested a review from johnslavik February 14, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants