Remove redundant import alias

This patch remove redundant import aliases and add pep8 hacking function
to check no redundant import aliases.

Co-Authored-By: Dao Cong Tien <tiendc@vn.fujitsu.com>

Change-Id: I3207cb9f0eb4b4a029b7e822b9c59cf48d1e0f9d
Closes-Bug: #1745527
This commit is contained in:
Luong Anh Tuan
2018-01-26 09:07:53 +07:00
parent 0c8c32e69e
commit 6edfd34a53
2 changed files with 15 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ log_warn = re.compile(
r"(.)*LOG\.(warn)\(\s*('|\"|_)") r"(.)*LOG\.(warn)\(\s*('|\"|_)")
unittest_imports_dot = re.compile(r"\bimport[\s]+unittest\b") unittest_imports_dot = re.compile(r"\bimport[\s]+unittest\b")
unittest_imports_from = re.compile(r"\bfrom[\s]+unittest\b") unittest_imports_from = re.compile(r"\bfrom[\s]+unittest\b")
re_redundant_import_alias = re.compile(r".*import (.+) as \1$")
@flake8ext @flake8ext
@@ -271,6 +272,18 @@ def check_builtins_gettext(logical_line, tokens, filename, lines, noqa):
yield (0, msg) yield (0, msg)
@flake8ext
def no_redundant_import_alias(logical_line):
"""Checking no redundant import alias.
https://bugs.launchpad.net/watcher/+bug/1745527
N342
"""
if re.match(re_redundant_import_alias, logical_line):
yield(0, "N342: No redundant import alias.")
def factory(register): def factory(register):
register(use_jsonutils) register(use_jsonutils)
register(check_assert_called_once_with) register(check_assert_called_once_with)
@@ -286,3 +299,4 @@ def factory(register):
register(check_log_warn_deprecated) register(check_log_warn_deprecated)
register(check_oslo_i18n_wrapper) register(check_oslo_i18n_wrapper)
register(check_builtins_gettext) register(check_builtins_gettext)
register(no_redundant_import_alias)

View File

@@ -16,7 +16,7 @@ import sys
import six import six
from watcher.notifications import base as notificationbase from watcher.notifications import base as notificationbase
from watcher.objects import base as base from watcher.objects import base
from watcher.objects import fields as wfields from watcher.objects import fields as wfields