Skip to content

Don't pass prefix_chars to add_argument_group unless given (Python 3.14 DeprecationWarning) - #377

Open
RClaudiuM wants to merge 1 commit into
lebrice:masterfrom
RClaudiuM:fix/368-add-argument-group-prefix-chars
Open

RClaudiuM wants to merge 1 commit into
lebrice:masterfrom
RClaudiuM:fix/368-add-argument-group-prefix-chars

Conversation

@RClaudiuM

Copy link
Copy Markdown

Fixes #368

On Python 3.14, every simple_parsing.ArgumentParser emits:

DeprecationWarning: The use of the undocumented 'prefix_chars' parameter in ArgumentParser.add_argument_group() is deprecated.

ArgumentParser.add_argument_group always forwarded prefix_chars=prefix_chars or self.prefix_chars, and argparse 3.14 warns whenever the keyword is present. When prefix_chars is omitted, argparse's _ArgumentGroup already falls back to the parser's prefix_chars (this is true on every supported Python version), so the override now forwards it only when the caller passes one explicitly. argument_default and conflict_handler are handled as before.

Added test/test_issue_368.py:

  • parsing a dataclass with DeprecationWarning turned into an error must not raise;
  • a group still inherits a custom prefix_chars / argument_default / conflict_handler from the parser.

Testing

  • pytest test/test_issue_368.py on 3.14: fails before the change (DeprecationWarning), passes after. Passes on 3.12 both before and after.
  • Full suite on 3.12 (uv sync --all-extras): same results before and after. The one failure, test_bools.py::test_bool_args_in_help, already fails on master.
  • Full suite on 3.14: the same 22 tests fail before and after (help text changes in 3.14 argparse, not related to this). With -W error::DeprecationWarning, it goes from 1006 failures to those same 22.
  • pre-commit run --all-files passes.

Python 3.14 deprecates passing prefix_chars to ArgumentParser.add_argument_group() and warns whenever the keyword is present. The group already inherits the parser's prefix_chars when it is omitted, so only forward it when the caller sets it explicitly.

Fixes lebrice#368

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeprecationWarning on Python 3.14: ArgumentParser.add_argument_group always passes prefix_chars

1 participant