Skip to content

Commit

Permalink
Only require tomli on Python < 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Mar 8, 2022
1 parent ed95b92 commit d40fed8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions bandit/core/config.py
Expand Up @@ -3,13 +3,17 @@
#
# SPDX-License-Identifier: Apache-2.0
import logging
import sys

import yaml

try:
import tomli
except ImportError:
tomli = None
if sys.version_info >= (3, 11):
import tomllib
else:
try:
import tomli as tomllib
except ImportError:
tomllib = None

from bandit.core import constants
from bandit.core import extension_loader
Expand Down Expand Up @@ -41,16 +45,16 @@ def __init__(self, config_file=None):
)

if config_file.endswith(".toml"):
if tomli is None:
if tomllib is None:
raise utils.ConfigError(
"toml parser not available, reinstall with toml extra",
config_file,
)

try:
with f:
self._config = tomli.load(f)["tool"]["bandit"]
except tomli.TOMLDecodeError as err:
self._config = tomllib.load(f)["tool"]["bandit"]
except tomllib.TOMLDecodeError as err:
LOG.error(err)
raise utils.ConfigError("Error parsing file.", config_file)
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -30,7 +30,7 @@ project_urls =
yaml =
PyYAML
toml =
tomli>=1.1.0
tomli>=1.1.0; python_version < "3.11"

[entry_points]
console_scripts =
Expand Down

0 comments on commit d40fed8

Please sign in to comment.