Merge "Remove hacking rules to enforce six usage"

This commit is contained in:
Zuul 2024-10-08 04:53:29 +00:00 committed by Gerrit Code Review
commit d6e223406f
5 changed files with 0 additions and 86 deletions

View File

@ -9,8 +9,3 @@ Mistral Specific Commandments
- [M001] Use LOG.warning(). LOG.warn() is deprecated. - [M001] Use LOG.warning(). LOG.warn() is deprecated.
- [M319] Enforce use of assertTrue/assertFalse - [M319] Enforce use of assertTrue/assertFalse
- [M320] Enforce use of assertIs/assertIsNot - [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.

View File

@ -81,37 +81,6 @@ def check_oslo_namespace_imports(logical_line):
yield (0, msg) 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): class BaseASTChecker(ast.NodeVisitor):
"""Provides a simple framework for writing AST-based checks. """Provides a simple framework for writing AST-based checks.

View File

@ -93,34 +93,6 @@ class BaseLoggingCheckTest(base.BaseTest):
self._assert_has_errors(code, checks.no_assert_true_false_is_not, self._assert_has_errors(code, checks.no_assert_true_false_is_not,
expected_errors=errors) 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): class TestLoggingWithWarn(BaseLoggingCheckTest):

View File

@ -87,24 +87,6 @@ class ContextView(dict):
def values(self): def values(self):
return [self[k] for k in self.keys()] 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): def __len__(self):
return len(self.keys()) return len(self.keys())

View File

@ -162,9 +162,5 @@ extension =
M001 = checks:CheckForLoggingIssues M001 = checks:CheckForLoggingIssues
M319 = checks:no_assert_equal_true_false M319 = checks:no_assert_equal_true_false
M320 = checks:no_assert_true_false_is_not 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 O323 = checks:check_oslo_namespace_imports
paths = ./mistral/hacking paths = ./mistral/hacking