Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make flake8-bandit work with latest bandit 1.7.3 too #23

Merged
merged 2 commits into from
Mar 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions flake8_bandit.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,27 @@ def _check_source(self):
):
return []

bnv = BanditNodeVisitor(
fname=self.filename,
fdata=None,
metaast=BanditMetaAst(),
testset=BanditTestSet(BanditConfig(), profile=config.profile),
debug=False,
nosec_lines=[],
metrics=Metrics(),
)

try:
bnv = BanditNodeVisitor(
fname=self.filename,
fdata=None,
metaast=BanditMetaAst(),
testset=BanditTestSet(BanditConfig(), profile=config.profile),
debug=False,
nosec_lines=[],
metrics=Metrics(),
)
except TypeError:
# bandit < 1.7.3 (https://github.com/tylerwince/flake8-bandit/issues/21)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would use the other PR approach, no real need to create this compatibility code. It just makes the code less maintainable and not a huge gain...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should pin versions in a package such as this one ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree @staticdev , the TypeError catch here makes an assumption that BanditNodeVisitor won't change again in future. We may just end up with a new generic TypeError being caused by the older call below, when in fact the root cause would be something else entirely.

Better to make two updates in this package, I feel:

bnv = BanditNodeVisitor(
fname=self.filename,
metaast=BanditMetaAst(),
testset=BanditTestSet(BanditConfig(), profile=config.profile),
debug=False,
nosec_lines=[],
metrics=Metrics(),
)
bnv.generic_visit(self.tree)
return [
{
Expand Down