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] 4bc6162515
Change-Id: If93609a56e341ff313063c0aa069d140528257b0
This commit is contained in:
parent
14f40d9a51
commit
e5454fbda2
@ -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.
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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):
|
||||
|
||||
|
@ -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())
|
||||
|
||||
|
4
tox.ini
4
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
|
||||
|
Loading…
Reference in New Issue
Block a user