From e5454fbda2dad89ffe32170d7e9d689677a8a90e Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 5 May 2022 13:01:48 +0900 Subject: [PATCH] Remove hacking rules to enforce six usage ... because these rules are no longer valid since usage of six library was removed[1]. This also removes the remaining implementations to keep compatibility with Python 2. [1] 4bc6162515f352af1fb1060ff337bce206cb2831 Change-Id: If93609a56e341ff313063c0aa069d140528257b0 --- HACKING.rst | 5 ---- mistral/hacking/checks.py | 31 ----------------------- mistral/tests/unit/hacking/test_checks.py | 28 -------------------- mistral/workflow/data_flow.py | 18 ------------- tox.ini | 4 --- 5 files changed, 86 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 49ee011d6..6c2dcd0d2 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -9,8 +9,3 @@ Mistral Specific Commandments - [M001] Use LOG.warning(). LOG.warn() is deprecated. - [M319] Enforce use of assertTrue/assertFalse - [M320] Enforce use of assertIs/assertIsNot -- [M327] Do not use xrange(). xrange() is not compatible with Python 3. Use - range() or six.moves.range() instead. -- [M328] Python 3: do not use dict.iteritems. -- [M329] Python 3: do not use dict.iterkeys. -- [M330] Python 3: do not use dict.itervalues. diff --git a/mistral/hacking/checks.py b/mistral/hacking/checks.py index 3f847eccf..0d062c20f 100644 --- a/mistral/hacking/checks.py +++ b/mistral/hacking/checks.py @@ -81,37 +81,6 @@ def check_oslo_namespace_imports(logical_line): yield (0, msg) -@core.flake8ext -def check_python3_xrange(logical_line): - if re.search(r"\bxrange\s*\(", logical_line): - yield (0, "M327: Do not use xrange(). 'xrange()' is not compatible " - "with Python 3. Use range() or range() instead.") - - -@core.flake8ext -def check_python3_no_iteritems(logical_line): - msg = ("M328: Use six.iteritems() instead of dict.iteritems().") - - if re.search(r".*\.iteritems\(\)", logical_line): - yield (0, msg) - - -@core.flake8ext -def check_python3_no_iterkeys(logical_line): - msg = ("M329: Use six.iterkeys() instead of dict.iterkeys().") - - if re.search(r".*\.iterkeys\(\)", logical_line): - yield (0, msg) - - -@core.flake8ext -def check_python3_no_itervalues(logical_line): - msg = ("M330: Use six.itervalues() instead of dict.itervalues().") - - if re.search(r".*\.itervalues\(\)", logical_line): - yield (0, msg) - - class BaseASTChecker(ast.NodeVisitor): """Provides a simple framework for writing AST-based checks. diff --git a/mistral/tests/unit/hacking/test_checks.py b/mistral/tests/unit/hacking/test_checks.py index 1e00693ce..4313057fc 100644 --- a/mistral/tests/unit/hacking/test_checks.py +++ b/mistral/tests/unit/hacking/test_checks.py @@ -93,34 +93,6 @@ class BaseLoggingCheckTest(base.BaseTest): self._assert_has_errors(code, checks.no_assert_true_false_is_not, expected_errors=errors) - def test_check_python3_xrange(self): - func = checks.check_python3_xrange - self.assertEqual(1, len(list(func('for i in xrange(10)')))) - self.assertEqual(1, len(list(func('for i in xrange (10)')))) - self.assertEqual(0, len(list(func('for i in range(10)')))) - self.assertEqual(0, len(list(func('for i in range(10)')))) - - def test_dict_iteritems(self): - self.assertEqual(1, len(list(checks.check_python3_no_iteritems( - "obj.iteritems()")))) - - self.assertEqual(0, len(list(checks.check_python3_no_iteritems( - "six.iteritems(ob))")))) - - def test_dict_iterkeys(self): - self.assertEqual(1, len(list(checks.check_python3_no_iterkeys( - "obj.iterkeys()")))) - - self.assertEqual(0, len(list(checks.check_python3_no_iterkeys( - "six.iterkeys(ob))")))) - - def test_dict_itervalues(self): - self.assertEqual(1, len(list(checks.check_python3_no_itervalues( - "obj.itervalues()")))) - - self.assertEqual(0, len(list(checks.check_python3_no_itervalues( - "six.itervalues(ob))")))) - class TestLoggingWithWarn(BaseLoggingCheckTest): diff --git a/mistral/workflow/data_flow.py b/mistral/workflow/data_flow.py index 40ee54436..1f809ccf8 100644 --- a/mistral/workflow/data_flow.py +++ b/mistral/workflow/data_flow.py @@ -87,24 +87,6 @@ class ContextView(dict): def values(self): return [self[k] for k in self.keys()] - def iteritems(self): - # NOTE: This is for compatibility with Python 2.7 - # YAQL converts output objects after they are evaluated - # to basic types and it uses six.iteritems() internally - # which calls d.items() in case of Python 2.7 and d.iteritems() - # for Python 2.7 - return iter(self.items()) - - def iterkeys(self): - # NOTE: This is for compatibility with Python 2.7 - # See the comment for iteritems(). - return iter(self.keys()) - - def itervalues(self): - # NOTE: This is for compatibility with Python 2.7 - # See the comment for iteritems(). - return iter(self.values()) - def __len__(self): return len(self.keys()) diff --git a/tox.ini b/tox.ini index 233609e01..dd362ab0d 100644 --- a/tox.ini +++ b/tox.ini @@ -134,9 +134,5 @@ extension = M001 = checks:CheckForLoggingIssues M319 = checks:no_assert_equal_true_false M320 = checks:no_assert_true_false_is_not - M327 = checks:check_python3_xrange - M328 = checks:check_python3_no_iteritems - M329 = checks:check_python3_no_iterkeys - M330 = checks:check_python3_no_itervalues O323 = checks:check_oslo_namespace_imports paths = ./mistral/hacking