Skip to content

Commit

Permalink
Fix crash on pyproject.toml without bandit config
Browse files Browse the repository at this point in the history
This is a naive fix for bandit crashing when it encounters a
`pyproject.toml` which does not contain any specific bandit
configuration.

This resolves the common failure mode that is seen, but does not cause
bandit to fall back to another configuration source if the
`pyproject.toml` does not contain any `tool.bandit` block.

Resolves PyCQA#1027
  • Loading branch information
javajawa committed Dec 3, 2023
1 parent 6b2e247 commit a5c7e77
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bandit/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self, config_file=None):

try:
with f:
self._config = tomllib.load(f)["tool"]["bandit"]
self._config = tomllib.load(f).get("tool", {}).get("bandit", {})
except tomllib.TOMLDecodeError as err:
LOG.error(err)
raise utils.ConfigError("Error parsing file.", config_file)
Expand Down

0 comments on commit a5c7e77

Please sign in to comment.