Skip to content

Commit 35825e4

Browse files
committed
refactor: reduce indentation
Use guard clauses and any to reduce level of nesting.
1 parent 7f87a9e commit 35825e4

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

bandit/core/manager.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ def discover_files(self, targets, recursive=False, excluded_paths=""):
215215

216216
# if there are command line provided exclusions add them to the list
217217
if excluded_paths:
218-
for path in excluded_paths.split(","):
219-
excluded_path_globs.append(path)
218+
excluded_path_globs.extend(excluded_paths.split(","))
220219

221220
# build list of files we will analyze
222221
for fname in targets:
@@ -401,24 +400,15 @@ def _is_file_included(
401400
:param enforce_glob: Can set to false to bypass extension check
402401
:return: Boolean indicating whether a file should be included
403402
"""
404-
return_value = False
405-
406-
# if this is matches a glob of files we look at, and it isn't in an
407-
# excluded path
408-
if _matches_glob_list(path, included_globs) or not enforce_glob:
409-
if not _matches_glob_list(path, excluded_path_strings) and not any(
410-
x in path for x in excluded_path_strings
411-
):
412-
return_value = True
413-
414-
return return_value
403+
if enforce_glob and not _matches_glob_list(path, included_globs):
404+
return False
405+
if _matches_glob_list(path, excluded_path_strings):
406+
return False
407+
return not any(x in path for x in excluded_path_strings)
415408

416409

417410
def _matches_glob_list(filename, glob_list):
418-
for glob in glob_list:
419-
if fnmatch.fnmatch(filename, glob):
420-
return True
421-
return False
411+
return any(fnmatch.fnmatch(filename, glob) for glob in glob_list)
422412

423413

424414
def _compare_baseline_results(baseline, results):

0 commit comments

Comments
 (0)