hacking: Prevent use of six
Spotted this in a review recently. We don't want people using six anymore. Change-Id: Ie107a95bc06390ab519d3b3af9b07103a9a14316 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
3 changed files with 27 additions and 0 deletions
@@ -140,6 +140,7 @@ mock_class_as_new_value_in_patching_re = re.compile(
rwlock_re = re.compile(
r"(?P<module_part>(oslo_concurrency\.)?(lockutils|fasteners))"
r"\.ReaderWriterLock\(.*\)")
six_re = re.compile(r"^(import six(\..*)?|from six(\..*)? import .*)$")
class BaseASTChecker(ast.NodeVisitor):
@@ -1030,3 +1031,18 @@ def check_lockutils_rwlocks(logical_line):
0,
msg % {'module': match.group('module_part')}
)
@core.flake8ext
def check_six(logical_line):
"""Check for use of six
nova is now Python 3-only so we don't want six. However, people might use
it out of habit and it will likely work since six is a transitive
dependency.
N370
"""
match = re.match(six_re, logical_line)
if match:
yield (0, "N370: Don't use or import six")
@@ -1020,3 +1020,13 @@ class HackingTestCase(test.NoDBTestCase):
nova_utils.ReaderWriterLock()
"""
self._assert_has_no_errors(code, checks.check_lockutils_rwlocks)
def test_check_six(self):
code = """
import six
from six import moves
from six.moves import range
import six.moves.urllib.parse as urlparse
"""
errors = [(x + 1, 0, 'N370') for x in range(4)]
self._assert_has_errors(code, checks.check_six, expected_errors=errors)
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.