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
sobolevn
reviewed
May 9, 2026
an arbitrary dunder name.
…eak-argparse-copy
| def __getattr__(self, name): | ||
| # _colorize's no_color themes are just all empty strings | ||
| # by directly using empty strings the import is avoided | ||
| if name.startswith("_"): |
Member
There was a problem hiding this comment.
Is there any reason not to check that this starts and ends with __ ?
We use this pattern elsewhere in the repo as well.
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