Skip to content

Commit 8bf7594

Browse files
authored
Argparse Python 3.14 enhancements (#1331)
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 <[email protected]>
1 parent a255dfa commit 8bf7594

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

bandit/cli/baseline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def initialize():
168168
epilog="Additional Bandit arguments such as severity filtering (-ll) "
169169
"can be added and will be passed to Bandit.",
170170
)
171+
if sys.version_info >= (3, 14):
172+
parser.suggest_on_error = True
173+
parser.color = False
171174

172175
parser.add_argument(
173176
"targets",

bandit/cli/config_generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def parse_args():
7676
description=help_description,
7777
formatter_class=argparse.RawTextHelpFormatter,
7878
)
79+
if sys.version_info >= (3, 14):
80+
parser.suggest_on_error = True
81+
parser.color = False
7982

8083
parser.add_argument(
8184
"--show-defaults",

bandit/cli/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ def main():
155155
description="Bandit - a Python source code security analyzer",
156156
formatter_class=argparse.RawDescriptionHelpFormatter,
157157
)
158+
if sys.version_info >= (3, 14):
159+
parser.suggest_on_error = True
160+
parser.color = False
161+
158162
parser.add_argument(
159163
"targets",
160164
metavar="targets",

0 commit comments

Comments
 (0)