Skip to content

Commit

Permalink
Fix 3.8 errors (#509)
Browse files Browse the repository at this point in the history
* add namespaces for parent attributes

* pylint formatting changes

* made bandit_parent a private attr

* remove _ast

* take 38 out of the pipeline failures

* add visit_Constant

* remove the nonexistant functions

* add pytest_cache to the ignore

* flake8 errors

* add data back to travis
  • Loading branch information
tylerwince authored and ericwb committed Jul 1, 2019
1 parent 45494c9 commit 3d08246
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
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

0 comments on commit 3d08246

Please sign in to comment.