From 9eea3951c79eb1aecf7b47a1fe5dcdee3fdef5bf Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 5 Nov 2015 14:28:54 +0100 Subject: [PATCH] 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 --- cinder/hacking/checks.py | 10 ++++++++++ tests-py3.txt | 1 + 2 files changed, 11 insertions(+) diff --git a/cinder/hacking/checks.py b/cinder/hacking/checks.py index a50f17f36..6fe208748 100644 --- a/cinder/hacking/checks.py +++ b/cinder/hacking/checks.py @@ -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: diff --git a/tests-py3.txt b/tests-py3.txt index b4de72841..68df6ef22 100644 --- a/tests-py3.txt +++ b/tests-py3.txt @@ -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 -- 2.45.2