Skip to content

Argparse Python 3.14 enhancements#1331

Merged
ericwb merged 1 commit into
PyCQA:mainfrom
ericwb:suggest_on_error
Nov 19, 2025
Merged

Argparse Python 3.14 enhancements#1331
ericwb merged 1 commit into
PyCQA:mainfrom
ericwb:suggest_on_error

Conversation

@ericwb
Copy link
Copy Markdown
Member

@ericwb ericwb commented Nov 19, 2025

The argparse lib in Py314 now can do suggestion of an argument when a typo is given. It only works on choices, but regardless it can be handy to users of Bandit. Besides Python 3.15 plans to enable this by default.

The other change is the color being disabled. Color in CLIs defaults to True in Python 3.14. And frankly it doesn't look good. Way too many colors being used.

https://docs.python.org/3/library/argparse.html#suggest-on-error

The argparse lib in Py314 now can do suggestion of an
argument when a typo is given. It only works on choices,
but regardless it can be handy to users of Bandit. Besides
Python 3.15 plans to enable this by default.

The other change is the color being disabled. Color in CLIs
defaults to True in Python 3.14. And frankly it doesn't look
good. Way too many colors being used.

https://docs.python.org/3/library/argparse.html#suggest-on-error

Signed-off-by: Eric Brown <eric_wade_brown@yahoo.com>
@ericwb ericwb self-assigned this Nov 19, 2025
@ericwb
Copy link
Copy Markdown
Member Author

ericwb commented Nov 19, 2025

This is what Python 3.14 looked like by default (color=True).

Screenshot 2025-11-18 at 5 47 09 PM

@ericwb
Copy link
Copy Markdown
Member Author

ericwb commented Nov 19, 2025

This is the suggest_on_error feature in action.

Erics-MacBook-Pro:bandit ericwb$ .tox/py314/bin/bandit examples/ --severity-level lo
usage: bandit [-h] [-r] [-a {file,vuln}] [-n CONTEXT_LINES] [-c CONFIG_FILE] [-p PROFILE]
              [-t TESTS] [-s SKIPS] [-l | --severity-level {all,low,medium,high}] [-i |
              --confidence-level {all,low,medium,high}]
              [-f {csv,custom,html,json,sarif,screen,txt,xml,yaml}] [--msg-template MSG_TEMPLATE]
              [-o [OUTPUT_FILE]] [-v] [-d] [-q] [--ignore-nosec] [-x EXCLUDED_PATHS]
              [-b BASELINE] [--ini INI_PATH] [--exit-zero] [--version]
              [targets ...]
bandit: error: argument --severity-level: invalid choice: 'lo', maybe you meant 'low'? (choose from all, low, medium, high)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Python 3.14 enhancements to the argparse configuration across Bandit's CLI entry points. The changes enable argument suggestions on typos (via suggest_on_error) and disable the default colored output (via color = False) for Python 3.14+, improving the user experience while maintaining compatibility with earlier Python versions.

  • Enables suggest_on_error for helpful argument suggestions when users make typos
  • Disables colored output which defaults to True in Python 3.14 but doesn't look good in Bandit's output
  • Applies changes consistently across all three CLI entry points (main, config_generator, and baseline)

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
bandit/cli/main.py Adds Python 3.14 argparse enhancements to the main Bandit CLI entry point
bandit/cli/config_generator.py Adds Python 3.14 argparse enhancements to the config generator CLI
bandit/cli/baseline.py Adds Python 3.14 argparse enhancements to the baseline CLI

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants