Remove old check for Python 2-3 compatibility

basestring and xrange no longer exist in Python 3 and any remaining
usage of these causes "undefined name" error.

Change-Id: I0782c6b521aedaad393ec7175414745c01d76048
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2026-01-06 23:07:42 +09:00
parent c0c6866a6b
commit b1fd82b989
3 changed files with 0 additions and 43 deletions

View File

@@ -46,8 +46,6 @@ assert_equal_with_true_re = re.compile(
assert_equal_with_false_re = re.compile(
r"assertEqual\(False,")
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
assert_no_xrange_re = re.compile(
r"\s*xrange\s*\(")
def _translation_checks_not_enforced(filename):
@@ -85,16 +83,6 @@ def no_log_warn(logical_line):
yield (0, "O339:Use LOG.warning() rather than LOG.warn()")
@core.flake8ext
def no_xrange(logical_line):
"""Disallow 'xrange()'
O340
"""
if assert_no_xrange_re.match(logical_line):
yield (0, "O340: Do not use xrange().")
@core.flake8ext
def no_translate_logs(logical_line, filename):
"""O341 - Don't translate logs.
@@ -144,21 +132,6 @@ def check_raised_localized_exceptions(logical_line, filename):
yield (logical_line.index(exception_msg), msg)
@core.flake8ext
def check_no_basestring(logical_line):
"""O343 - basestring is not Python3-compatible.
:param logical_line: The logical line to check.
:returns: None if the logical line passes the check, otherwise a tuple
is yielded that contains the offending index in logical line and a
message describe the check validation failure.
"""
if re.search(r"\bbasestring\b", logical_line):
msg = ("O343: basestring is not Python3-compatible, use "
"six.string_types instead.")
yield (0, msg)
@core.flake8ext
def check_no_eventlet_imports(logical_line):
"""O345 - Usage of Python eventlet module not allowed.

View File

@@ -87,13 +87,6 @@ class HackingTestCase(base.BaseTestCase):
self.assertEqual(0, len(list(checks.no_log_warn(
"LOG.warning()"))))
def test_no_xrange(self):
self.assertEqual(1, len(list(checks.no_xrange(
"xrange(45)"))))
self.assertEqual(0, len(list(checks.no_xrange(
"range(45)"))))
def test_no_log_translations(self):
for log in checks._all_log_levels:
for hint in checks._all_hints:
@@ -125,13 +118,6 @@ class HackingTestCase(base.BaseTestCase):
self.assertLinePasses(f, "raise KeyError('Error text')",
'neutron_lib/tests/unit/mytest.py')
def test_check_no_basestring(self):
self.assertEqual(1, len(list(checks.check_no_basestring(
"isinstance('foo', basestring)"))))
self.assertEqual(0, len(list(checks.check_no_basestring(
"isinstance('foo', six.string_types)"))))
def test_check_no_eventlet_imports(self):
f = checks.check_no_eventlet_imports
self.assertLinePasses(f, 'from not_eventlet import greenthread')

View File

@@ -117,10 +117,8 @@ extension =
O323 = checks:assert_equal_true_or_false
O324 = checks:no_mutable_default_args
O339 = checks:no_log_warn
O340 = checks:no_xrange
O341 = checks:no_translate_logs
O342 = checks:check_raised_localized_exceptions
O343 = checks:check_no_basestring
O345 = checks:check_no_eventlet_imports
O346 = checks:check_line_continuation_no_backslash
paths =