Fix known_args_namespace containing duplicate append-action values#14207
Open
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Open
Fix known_args_namespace containing duplicate append-action values#14207Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Conversation
The third parse_known_args call re-parsed into the existing known_args_namespace, causing append-action arguments like -W to be duplicated. Additionally, replace copy.copy with copy.deepcopy for all namespace copies to prevent shared mutable state between parses. Fixes pytest-dev#13484 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
for more information, see https://pre-commit.ci
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.
Summary
Fixes #13484
Config.known_args_namespacecontains duplicate values for append-action arguments (e.g.,-Werrorproducespythonwarnings=['error', 'error']).Two root causes:
Third parse re-uses existing namespace: After the initial
known_args_namespaceis populated (line 1535), a thirdparse_known_argscall (line 1553) re-parses into the same namespace object. For append-action arguments, this appends values that are already present.Shallow copy shares mutable state:
copy.copy()on anargparse.Namespacecreates a shallow copy — list attributes (like those from append actions) are shared between the original and the copy. Parsing into the copy mutates the original.Fix: Replace the third parse's direct namespace reuse with a fresh
deepcopy(self.option), and change allcopy.copy(self.option)calls tocopy.deepcopy(self.option).Test plan
test_append_args_not_duplicatedverifying-Werrorproduces exactly['error']test_config.pytests pass (1 pre-existing subprocess failure)test_warnings.pytests pass (1 pre-existing subprocess failure)🤖 Generated with Claude Code