Skip to content

Commit 36fc7be

Browse files
authored
language and linting updates (#1015)
* language and linting updates - converted several format strings to f-strings - sorted and tidied imports (isort) - cleaned some whitespace - updated pylintrc to exclude examples - updated pylintrc to specify all currently failing cases, so any new ones could be part of pre-commit if so wished * Update config.py match pep8 for imports * Update pylintrc stylistic
1 parent 3260f13 commit 36fc7be

29 files changed

+79
-94
lines changed

bandit/cli/config_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ def main():
158158

159159
for skip in skips:
160160
if not extension_loader.MANAGER.check_id(skip):
161-
raise RuntimeError("unknown ID in skips: %s" % skip)
161+
raise RuntimeError(f"unknown ID in skips: {skip}")
162162

163163
for test in tests:
164164
if not extension_loader.MANAGER.check_id(test):
165-
raise RuntimeError("unknown ID in tests: %s" % test)
165+
raise RuntimeError(f"unknown ID in tests: {test}")
166166

167167
tpl = "# {0} : {1}"
168168
test_list = [

bandit/cli/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ def main():
371371
parser.add_argument(
372372
"--version",
373373
action="version",
374-
version="%(prog)s {version}\n python version = {python}".format(
375-
version=bandit.__version__, python=python_ver
376-
),
374+
version=f"%(prog)s {bandit.__version__}\n"
375+
f" python version = {python_ver}",
377376
)
378377

379378
parser.set_defaults(debug=False)
@@ -387,7 +386,7 @@ def main():
387386
blacklist_info = []
388387
for a in extension_mgr.blacklist.items():
389388
for b in a[1]:
390-
blacklist_info.append("{}\t{}".format(b["id"], b["name"]))
389+
blacklist_info.append(f"{b['id']}\t{b['name']}")
391390

392391
plugin_list = "\n\t".join(sorted(set(plugin_info + blacklist_info)))
393392
dedent_text = textwrap.dedent(

bandit/core/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from bandit.core import extension_loader
2020
from bandit.core import utils
2121

22-
2322
LOG = logging.getLogger(__name__)
2423

2524

bandit/core/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __repr__(self):
3434
3535
:return: A string representation of the object
3636
"""
37-
return "<Context %s>" % self._context
37+
return f"<Context {self._context}>"
3838

3939
@property
4040
def call_args(self):

bandit/core/docs_utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ def get_url(bid):
1616

1717
info = extension_loader.MANAGER.plugins_by_id.get(bid)
1818
if info is not None:
19-
return "{}plugins/{}_{}.html".format(
20-
base_url,
21-
bid.lower(),
22-
info.plugin.__name__,
23-
)
19+
return f"{base_url}plugins/{bid.lower()}_{info.plugin.__name__}.html"
2420

2521
info = extension_loader.MANAGER.blacklist_by_id.get(bid)
2622
if info is not None:

bandit/core/extension_loader.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_has_id(plugin):
4242
if not hasattr(plugin.plugin, "_test_id"):
4343
# logger not setup yet, so using print
4444
print(
45-
"WARNING: Test '%s' has no ID, skipping." % plugin.name,
45+
f"WARNING: Test '{plugin.name}' has no ID, skipping.",
4646
file=sys.stderr,
4747
)
4848
return False
@@ -82,16 +82,16 @@ def validate_profile(self, profile):
8282
"""Validate that everything in the configured profiles looks good."""
8383
for inc in profile["include"]:
8484
if not self.check_id(inc):
85-
raise ValueError("Unknown test found in profile: %s" % inc)
85+
raise ValueError(f"Unknown test found in profile: {inc}")
8686

8787
for exc in profile["exclude"]:
8888
if not self.check_id(exc):
89-
raise ValueError("Unknown test found in profile: %s" % exc)
89+
raise ValueError(f"Unknown test found in profile: {exc}")
9090

9191
union = set(profile["include"]) & set(profile["exclude"])
9292
if len(union) > 0:
9393
raise ValueError(
94-
"Non-exclusive include/exclude test sets: %s" % union
94+
f"Non-exclusive include/exclude test sets: {union}"
9595
)
9696

9797
def check_id(self, test):

bandit/core/manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from bandit.core import node_visitor as b_node_visitor
2424
from bandit.core import test_set as b_test_set
2525

26-
2726
LOG = logging.getLogger(__name__)
2827
NOSEC_COMMENT = re.compile(r"#\s*nosec:?\s*(?P<tests>[^#]+)?#?")
2928
NOSEC_COMMENT_TESTS = re.compile(r"(?:(B\d+|[a-z_]+),?)+", re.IGNORECASE)
@@ -195,8 +194,8 @@ def output_results(
195194

196195
except Exception as e:
197196
raise RuntimeError(
198-
"Unable to output report using '%s' formatter: "
199-
"%s" % (output_format, str(e))
197+
f"Unable to output report using "
198+
f"'{output_format}' formatter: {str(e)}"
200199
)
201200

202201
def discover_files(self, targets, recursive=False, excluded_paths=""):

bandit/core/meta_ast.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import collections
66
import logging
77

8-
98
LOG = logging.getLogger(__name__)
109

1110

@@ -40,7 +39,7 @@ def __str__(self):
4039
"""
4140
tmpstr = ""
4241
for k, v in self.nodes.items():
43-
tmpstr += "Node: %s\n" % k
44-
tmpstr += "\t%s\n" % str(v)
45-
tmpstr += "Length: %s\n" % len(self.nodes)
42+
tmpstr += f"Node: {k}\n"
43+
tmpstr += f"\t{str(v)}\n"
44+
tmpstr += f"Length: {len(self.nodes)}\n"
4645
return tmpstr

bandit/core/node_visitor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from bandit.core import tester as b_tester
1111
from bandit.core import utils as b_utils
1212

13-
1413
LOG = logging.getLogger(__name__)
1514

1615

bandit/core/test_set.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from bandit.core import blacklisting
99
from bandit.core import extension_loader
1010

11-
1211
LOG = logging.getLogger(__name__)
1312

1413

0 commit comments

Comments
 (0)