-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-144782: Make sure that ArgumentParser instances are pickleable #144783
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
Open
mauvilsa
wants to merge
10
commits into
python:main
Choose a base branch
from
mauvilsa:argparse-pickleable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−4
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8eb006e
Make sure that ArgumentParser instances are pickleable
mauvilsa 262f062
Apply suggestion from @johnslavik
mauvilsa eb80248
Update Misc/NEWS.d/next/Library/2026-02-13-14-20-10.gh-issue-144782.0…
mauvilsa f1f2876
Apply suggestions from code review
mauvilsa 37b0a2b
Update Lib/argparse.py
mauvilsa d196726
Test all protocols
mauvilsa 2f28bdc
Add some documentation suggestions
johnslavik 858c44e
Apply suggestion from @mauvilsa
mauvilsa 1525000
Merge pull request #1 from johnslavik/argparse-pickleable-final-sugge…
mauvilsa c7d87ef
Reframe news entry, remove versionadded (#2)
johnslavik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2026-02-13-14-20-10.gh-issue-144782.0Y8TKj.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix :class:`argparse.ArgumentParser` to be :mod:`pickleable <pickle>`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work with color?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this fix, currently it does work with color. Should we also test with color?
I agree that it is difficult to guarantee pickleablility, but running all existing tests with pickle seems unnecessary. What would make a parser unpickleable is just assigning an unpickleable object. So only need one test for each path of the code where objects could be assigned. Instead of more tests could also be part of the review process, watching out for locally defined functions and lambdas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add tests for each concrete case after we found that it breaks pickle. But we cannot guarantee that future changes (maybe in other part of the stdlib) will not break it for not tested cases.
For example, currently it works with color. But the color machinery is outside of the scope of the
argparsemodule. So, the test with color is necessary, without it we cannot catch regression.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I understand. I can add the test with color. I can also analyze the code a bit to see if there are more tests cases that seem important to prevent regressions. Apart from this, is there any way for me to get notified when an argparse pull request in cpython is ready for review? I can be the one looking out for changes that could make parsers unpickleable.