]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port cinder.hacking to Python 3
authorVictor Stinner <vstinner@redhat.com>
Thu, 5 Nov 2015 13:28:54 +0000 (14:28 +0100)
committerVictor Stinner <vstinner@redhat.com>
Thu, 5 Nov 2015 16:36:32 +0000 (17:36 +0100)
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

cinder/hacking/checks.py
tests-py3.txt

index a50f17f367bf8d272d868632ea7ddc902b658d1d..6fe208748d12df910e193597d07c23f87cddbf4d 100644 (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:
index b4de72841016ce00f0070bc85361fb61a5e72ba6..68df6ef22982315f303ac2b742a1ca19fea1ae7e 100644 (file)
@@ -62,6 +62,7 @@ cinder.tests.unit.test_evaluator
 cinder.tests.unit.test_exception
 cinder.tests.unit.test_glusterfs
 cinder.tests.unit.test_gpfs
+cinder.tests.unit.test_hacking
 cinder.tests.unit.test_hitachi_hbsd_horcm_fc
 cinder.tests.unit.test_hitachi_hbsd_snm2_fc
 cinder.tests.unit.test_hitachi_hbsd_snm2_iscsi