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

Replace setattr #493

Merged
merged 6 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions bandit/core/node_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def post_visit(self, node):

# HACK(tkelsey): this is needed to clean up post-recursion stuff that
# gets setup in the visit methods for these node types.
if isinstance(node, ast.FunctionDef) or isinstance(node, ast.ClassDef):
if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
self.namespace = b_utils.namespace_path_split(self.namespace)[0]

def generic_visit(self, node):
Expand All @@ -238,20 +238,19 @@ def generic_visit(self, node):
for idx, item in enumerate(value):
if isinstance(item, ast.AST):
if idx < max_idx:
setattr(item, '_bandit_sibling', value[idx + 1])
item._bandit_sibling = value[idx + 1]
else:
setattr(item, '_bandit_sibling', None)
setattr(item, '_bandit_parent', node)
item._bandit_sibling = None
item._bandit_parent = node

if self.pre_visit(item):
self.visit(item)
self.generic_visit(item)
self.post_visit(item)

elif isinstance(value, ast.AST):
setattr(value, '_bandit_sibling', None)
setattr(value, '_bandit_parent', node)

value._bandit_sibling = None
value._bandit_parent = node
if self.pre_visit(value):
self.visit(value)
self.generic_visit(value)
Expand Down
7 changes: 4 additions & 3 deletions bandit/core/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def __init__(self, name, plugin):
# this dresses up the blacklist to look like a plugin, but
# the '_checks' data comes from the blacklist information.
# the '_config' is the filtered blacklist data set.
setattr(blacklisting.blacklist, "_test_id", 'B001')
setattr(blacklisting.blacklist, "_checks", blacklist.keys())
setattr(blacklisting.blacklist, "_config", blacklist)
blacklisting.blacklist._test_id = "B001"
blacklisting.blacklist._checks = blacklist.keys()
blacklisting.blacklist._config = blacklist

return [Wrapper('blacklist', blacklisting.blacklist)]

def _load_tests(self, config, plugins):
Expand Down
4 changes: 2 additions & 2 deletions bandit/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def linerange(node):
for key in strip.keys():
if hasattr(node, key):
strip[key] = getattr(node, key)
setattr(node, key, [])
node.key = []
Copy link

Choose a reason for hiding this comment

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

This is bug.

>>> key = "foo"
>>> setattr(node, key, [])
>>> node.foo
[]
>>> node.key
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Node' object has no attribute 'key'


lines_min = 9999999999
lines_max = -1
Expand All @@ -222,7 +222,7 @@ def linerange(node):

for key in strip.keys():
if strip[key] is not None:
setattr(node, key, strip[key])
node.key = strip[key]
Copy link

Choose a reason for hiding this comment

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

Here too


if lines_max > -1:
return list(range(lines_min, lines_max + 1))
Expand Down