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

Fix 3.8 errors #509

Merged
merged 12 commits into from
Jul 1, 2019
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ matrix:
sudo: true
- python: pypy
env: TOXENV=pypy
allow_failures:
- python: 3.8-dev
env: TOXENV=py38
dist: xenial
sudo: true

notifications:
email:
- lhinds@protonmail.com
Expand Down
17 changes: 17 additions & 0 deletions bandit/core/node_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ def visit_ImportFrom(self, node):
self.context['name'] = nodename.name
self.update_scores(self.tester.run_tests(self.context, 'ImportFrom'))

def visit_Constant(self, node):
'''Visitor for AST Constant nodes

call the appropriate method for the node type.
this maintains compatibility with <3.6 and 3.8+

This code is heavily influenced by Anthony Sottile (@asottile) here:
https://bugs.python.org/msg342486

:param node: The node that is being inspected
:return: -
'''
if isinstance(node.value, str):
self.visit_Str(node)
elif isinstance(node.value, bytes):
self.visit_Bytes(node)

def visit_Str(self, node):
'''Visitor for AST String nodes

Expand Down
11 changes: 5 additions & 6 deletions bandit/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import _ast
import ast
import logging
import os.path
Expand Down Expand Up @@ -46,11 +45,11 @@ def _get_attr_qual_name(node, aliases):
:param aliases: Import aliases dictionary
:returns: Qualified name referred to by the attribute or name.
'''
if isinstance(node, _ast.Name):
if isinstance(node, ast.Name):
if node.id in aliases:
return aliases[node.id]
return node.id
elif isinstance(node, _ast.Attribute):
elif isinstance(node, ast.Attribute):
name = '%s.%s' % (_get_attr_qual_name(node.value, aliases), node.attr)
if name in aliases:
return aliases[name]
Expand All @@ -60,11 +59,11 @@ def _get_attr_qual_name(node, aliases):


def get_call_name(node, aliases):
if isinstance(node.func, _ast.Name):
if isinstance(node.func, ast.Name):
if deepgetattr(node, 'func.id') in aliases:
return aliases[deepgetattr(node, 'func.id')]
return deepgetattr(node, 'func.id')
elif isinstance(node.func, _ast.Attribute):
elif isinstance(node.func, ast.Attribute):
return _get_attr_qual_name(node.func, aliases)
else:
return ""
Expand All @@ -76,7 +75,7 @@ def get_func_name(node):

def get_qual_attr(node, aliases):
prefix = ""
if isinstance(node, _ast.Attribute):
if isinstance(node, ast.Attribute):
try:
val = deepgetattr(node, 'value.id')
if val in aliases:
Expand Down