From 6edfd34a533a35d198b00b61255fd38a5147c2ed Mon Sep 17 00:00:00 2001 From: Luong Anh Tuan Date: Fri, 26 Jan 2018 09:07:53 +0700 Subject: [PATCH] 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 Change-Id: I3207cb9f0eb4b4a029b7e822b9c59cf48d1e0f9d Closes-Bug: #1745527 --- watcher/hacking/checks.py | 14 ++++++++++++++ watcher/notifications/exception.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/watcher/hacking/checks.py b/watcher/hacking/checks.py index 6d4fab130..bd8351146 100644 --- a/watcher/hacking/checks.py +++ b/watcher/hacking/checks.py @@ -60,6 +60,7 @@ log_warn = re.compile( r"(.)*LOG\.(warn)\(\s*('|\"|_)") unittest_imports_dot = re.compile(r"\bimport[\s]+unittest\b") unittest_imports_from = re.compile(r"\bfrom[\s]+unittest\b") +re_redundant_import_alias = re.compile(r".*import (.+) as \1$") @flake8ext @@ -271,6 +272,18 @@ def check_builtins_gettext(logical_line, tokens, filename, lines, noqa): 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): register(use_jsonutils) register(check_assert_called_once_with) @@ -286,3 +299,4 @@ def factory(register): register(check_log_warn_deprecated) register(check_oslo_i18n_wrapper) register(check_builtins_gettext) + register(no_redundant_import_alias) diff --git a/watcher/notifications/exception.py b/watcher/notifications/exception.py index 68fc1eb03..7de5e09b0 100644 --- a/watcher/notifications/exception.py +++ b/watcher/notifications/exception.py @@ -16,7 +16,7 @@ import sys import six 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