Port cinder.hacking to Python 3

Fix the N325 check on Python 3: the AST changed between Python 2 and
Python 3 for try/except.

tox.ini: Add cinder.tests.unit.test_hacking to Python 3.4.

Partial-Implements: blueprint cinder-python3
Change-Id: I7c7d1c5e52f525ade14b13ecf2dec1681997da22
This commit is contained in:
Victor Stinner
2015-11-05 14:28:54 +01:00
parent 76c42fc70a
commit 9eea3951c7
2 changed files with 11 additions and 0 deletions

View File

@@ -184,6 +184,7 @@ class CheckForStrUnicodeExc(BaseASTChecker):
self.name = []
self.already_checked = []
# Python 2
def visit_TryExcept(self, node):
for handler in node.handlers:
if handler.name:
@@ -193,6 +194,15 @@ class CheckForStrUnicodeExc(BaseASTChecker):
else:
super(CheckForStrUnicodeExc, self).generic_visit(node)
# Python 3
def visit_ExceptHandler(self, node):
if node.name:
self.name.append(node.name)
super(CheckForStrUnicodeExc, self).generic_visit(node)
self.name = self.name[:-1]
else:
super(CheckForStrUnicodeExc, self).generic_visit(node)
def visit_Call(self, node):
if self._check_call_names(node, ['str', 'unicode']):
if node not in self.already_checked: