gh-149614 - Restore deepcopiability of argparse.ArgumentParser instances#149617
Open
DavidCEllis wants to merge 10 commits intopython:mainfrom
Open
gh-149614 - Restore deepcopiability of argparse.ArgumentParser instances#149617DavidCEllis wants to merge 10 commits intopython:mainfrom
DavidCEllis wants to merge 10 commits intopython:mainfrom
Conversation
| parser.add_argument('bar', nargs='?', default='baz') | ||
| return parser | ||
|
|
||
| def test_copiable(self): |
Member
There was a problem hiding this comment.
I think we want @force_not_colorized on these tests right?
Separately, we may also be able to fold copiable and deepcopiable into one test, since these are pretty much the same.
Contributor
Author
There was a problem hiding this comment.
I've left these as two tests for now as there's testing for the different copy/deepcopy behaviour
| import copy | ||
| parser = self._get_parser() | ||
| parser2 = copy.deepcopy(parser) | ||
| ns = parser2.parse_args(['--foo', '123', 'quux']) |
Member
There was a problem hiding this comment.
It'd be more robust to mutate parser2 (e.g. add_argument) and assert parser doesn't see it. As written, the test would still pass if deepcopy silently returned a shallow copy or even the same object.
sobolevn
reviewed
May 9, 2026
an arbitrary dunder name.
…eak-argparse-copy
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With the creation of the
_ColorlessThemeto avoid importing_colorizeearly the new class unfortunately was returning empty strings for__deepcopy__along with other dunder methods which broke deepcopy.I've added tests for
copyanddeepcopybased on the test forpickle.Being more cautious, I've narrowed the class to only returning empty strings on attributes matching those taken from
_colorize.This does mean making sure the set remains in sync which could be more annoying to maintain, it would also be possible to just exclude anything starting with
_. I've updated the test that checks this theme to directly check they are in sync.TypeErrorwhen trying to deepcopyargparse.ArgumentParser()#149614