summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-10-09 09:43:38 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2019-10-09 09:54:52 +0200
commit1e05190ef09f6bdb3d4ce8573e2548853df30cdf (patch)
treeed6017f425c8c04551411ee4aa6e6c89e73ace96
parent3f86141e608afad6b9fb69fcc13b1cf5a8d7eb9f (diff)
downloadpylint-git-1e05190ef09f6bdb3d4ce8573e2548853df30cdf.tar.gz
``import-outside-toplevel`` is emitted for ``ImportFrom`` nodes as well.
Close #3175
-rw-r--r--ChangeLog4
-rw-r--r--pylint/__init__.py18
-rw-r--r--pylint/checkers/imports.py1
-rw-r--r--pylint/checkers/similar.py2
-rw-r--r--pylint/lint.py4
-rw-r--r--pylint/reporters/__init__.py3
-rw-r--r--tests/functional/b/bad_reversed_sequence.py8
-rw-r--r--tests/functional/b/bugfix_local_scope_metaclass_1177.py4
-rw-r--r--tests/functional/c/consider_using_enumerate.py1
-rw-r--r--tests/functional/import_outside_toplevel.py4
-rw-r--r--tests/functional/import_outside_toplevel.txt1
-rw-r--r--tests/functional/r/redefined_outer_name_type_checking.py1
-rw-r--r--tests/functional/s/string_formatting.py2
-rw-r--r--tests/functional/s/string_formatting_py3.py2
-rw-r--r--tests/functional/u/unbalanced_tuple_unpacking.py2
-rw-r--r--tests/input/func_w0401_disabled_in_func.py2
16 files changed, 31 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index 69f5ec6b5..409dfec8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,10 @@ Release date: TBA
Close #3148
+* ``import-outside-toplevel`` is emitted for ``ImportFrom`` nodes as well.
+
+ Close #3175
+
What's New in Pylint 2.4.2?
===========================
diff --git a/pylint/__init__.py b/pylint/__init__.py
index a5d43d123..89809389b 100644
--- a/pylint/__init__.py
+++ b/pylint/__init__.py
@@ -9,35 +9,35 @@
import sys
-from .__pkginfo__ import version as __version__
+from pylint.__pkginfo__ import version as __version__
+from pylint.checkers.similar import Run as SimilarRun
+from pylint.epylint import Run as EpylintRun
+from pylint.lint import Run as PylintRun
+from pylint.pyreverse.main import Run as PyreverseRun
def run_pylint():
"""run pylint"""
- from pylint.lint import Run
try:
- Run(sys.argv[1:])
+ PylintRun(sys.argv[1:])
except KeyboardInterrupt:
sys.exit(1)
def run_epylint():
"""run pylint"""
- from pylint.epylint import Run
- Run()
+ EpylintRun()
def run_pyreverse():
"""run pyreverse"""
- from pylint.pyreverse.main import Run
- Run(sys.argv[1:])
+ PyreverseRun(sys.argv[1:])
def run_symilar():
"""run symilar"""
- from pylint.checkers.similar import Run
- Run(sys.argv[1:])
+ SimilarRun(sys.argv[1:])
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index 710eb28ae..42d4362df 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -520,6 +520,7 @@ class ImportsChecker(BaseChecker):
self._check_wildcard_imports(node, imported_module)
self._check_same_line_imports(node)
self._check_reimport(node, basename=basename, level=node.level)
+ self._check_toplevel(node)
if isinstance(node.parent, astroid.Module):
# Allow imports nested
diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py
index d87a2b132..019b55fc5 100644
--- a/pylint/checkers/similar.py
+++ b/pylint/checkers/similar.py
@@ -19,6 +19,7 @@
import sys
from collections import defaultdict
+from getopt import getopt
from itertools import groupby
import astroid
@@ -412,7 +413,6 @@ def Run(argv=None):
"""standalone command line access point"""
if argv is None:
argv = sys.argv[1:]
- from getopt import getopt
s_opts = "hdi"
l_opts = (
diff --git a/pylint/lint.py b/pylint/lint.py
index bbb01d35e..a98970b78 100644
--- a/pylint/lint.py
+++ b/pylint/lint.py
@@ -73,7 +73,7 @@ from astroid import modutils
from astroid.__pkginfo__ import version as astroid_version
from astroid.builder import AstroidBuilder
-from pylint import checkers, config, exceptions, interfaces, reporters
+from pylint import __pkginfo__, checkers, config, exceptions, interfaces, reporters
from pylint.__pkginfo__ import version
from pylint.constants import MAIN_CHECKER_NAME, MSG_TYPES, OPTION_RGX
from pylint.message import Message, MessageDefinitionStore, MessagesHandlerMixIn
@@ -1761,8 +1761,6 @@ group are mutually exclusive.",
def cb_generate_manpage(self, *args, **kwargs):
"""optik callback for sample config file generation"""
- from pylint import __pkginfo__
-
self.linter.generate_manpage(__pkginfo__)
sys.exit(0)
diff --git a/pylint/reporters/__init__.py b/pylint/reporters/__init__.py
index fe767bcc5..f01629bce 100644
--- a/pylint/reporters/__init__.py
+++ b/pylint/reporters/__init__.py
@@ -19,6 +19,7 @@
"""utilities methods and classes for reporters"""
+from pylint import utils
from pylint.reporters.base_reporter import BaseReporter
from pylint.reporters.collecting_reporter import CollectingReporter
from pylint.reporters.json_reporter import JSONReporter
@@ -27,8 +28,6 @@ from pylint.reporters.reports_handler_mix_in import ReportsHandlerMixIn
def initialize(linter):
"""initialize linter with reporters in this package """
- from pylint import utils
-
utils.register_plugins(linter, __path__[0])
diff --git a/tests/functional/b/bad_reversed_sequence.py b/tests/functional/b/bad_reversed_sequence.py
index 6cfac5bed..f423dd2d6 100644
--- a/tests/functional/b/bad_reversed_sequence.py
+++ b/tests/functional/b/bad_reversed_sequence.py
@@ -1,9 +1,9 @@
""" Checks that reversed() receive proper argument """
# pylint: disable=missing-docstring, useless-object-inheritance
# pylint: disable=too-few-public-methods,no-self-use,no-absolute-import
-from collections import deque
+from collections import deque, OrderedDict
+from enum import IntEnum
-__revision__ = 0
class GoodReversed(object):
""" Implements __reversed__ """
@@ -61,8 +61,6 @@ def test(path):
def test_dict_ancestor_and_reversed():
"""Don't emit for subclasses of dict, with __reversed__ implemented."""
- from collections import OrderedDict
-
class Child(dict):
def __reversed__(self):
return reversed(range(10))
@@ -73,8 +71,6 @@ def test_dict_ancestor_and_reversed():
def test_dont_emit_for_reversing_enums():
"""Don't emit when reversing enum classes"""
- from enum import IntEnum
-
class Color(IntEnum):
RED = 1
GREEN = 2
diff --git a/tests/functional/b/bugfix_local_scope_metaclass_1177.py b/tests/functional/b/bugfix_local_scope_metaclass_1177.py
index 8904f6fb2..22c07a330 100644
--- a/tests/functional/b/bugfix_local_scope_metaclass_1177.py
+++ b/tests/functional/b/bugfix_local_scope_metaclass_1177.py
@@ -1,5 +1,5 @@
# pylint: disable=missing-docstring,too-few-public-methods,import-error
-from UNINFERABLE import ImportedMetaclass
+from UNINFERABLE import ImportedMetaclass, ImportedMetaclass2
class Meta(type):
@@ -48,8 +48,6 @@ def imported_and_nested_scope1():
def imported_and_nested_scope2():
- from UNINFERABLE import ImportedMetaclass2
-
class ClassImp3(metaclass=ImportedMetaclass2):
pass
diff --git a/tests/functional/c/consider_using_enumerate.py b/tests/functional/c/consider_using_enumerate.py
index 758375c37..cff00aeec 100644
--- a/tests/functional/c/consider_using_enumerate.py
+++ b/tests/functional/c/consider_using_enumerate.py
@@ -49,6 +49,7 @@ def good():
for index in range(len(iterable)):
yield other_obj[index]
+ # pylint: disable=import-outside-toplevel
from unknown import unknown
for index in range(unknown(iterable)):
yield iterable[index]
diff --git a/tests/functional/import_outside_toplevel.py b/tests/functional/import_outside_toplevel.py
index 0575e59b2..762faa551 100644
--- a/tests/functional/import_outside_toplevel.py
+++ b/tests/functional/import_outside_toplevel.py
@@ -32,3 +32,7 @@ class C:
def k(flag):
if flag:
import tabnanny # [import-outside-toplevel]
+
+
+def j():
+ from collections import defaultdict # [import-outside-toplevel]
diff --git a/tests/functional/import_outside_toplevel.txt b/tests/functional/import_outside_toplevel.txt
index 53f9595d2..d15db6947 100644
--- a/tests/functional/import_outside_toplevel.txt
+++ b/tests/functional/import_outside_toplevel.txt
@@ -5,3 +5,4 @@ import-outside-toplevel:22:i:Import outside toplevel (random, socket)
import-outside-toplevel:26:C:Import outside toplevel (tokenize)
import-outside-toplevel:29:C.j:Import outside toplevel (turtle)
import-outside-toplevel:34:k:Import outside toplevel (tabnanny)
+import-outside-toplevel:38:j:Import outside toplevel (collections)
diff --git a/tests/functional/r/redefined_outer_name_type_checking.py b/tests/functional/r/redefined_outer_name_type_checking.py
index b708902e0..399fc8cea 100644
--- a/tests/functional/r/redefined_outer_name_type_checking.py
+++ b/tests/functional/r/redefined_outer_name_type_checking.py
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING
class Cls:
def func(self, stuff: defaultdict):
# This import makes the definition work.
+ # pylint: disable=import-outside-toplevel
from collections import defaultdict
obj = defaultdict()
diff --git a/tests/functional/s/string_formatting.py b/tests/functional/s/string_formatting.py
index 82f6d112d..bb7166fde 100644
--- a/tests/functional/s/string_formatting.py
+++ b/tests/functional/s/string_formatting.py
@@ -134,7 +134,7 @@ def issue338():
trying to infer EmptyNodes (resulted after mocking the
members of namedtuples).
"""
- from collections import namedtuple
+ from collections import namedtuple # pylint: disable=import-outside-toplevel
class Crash(namedtuple("C", "foo bar")):
""" Looking for attributes in __str__ will crash,
diff --git a/tests/functional/s/string_formatting_py3.py b/tests/functional/s/string_formatting_py3.py
index c27e9719e..3cdd60eb2 100644
--- a/tests/functional/s/string_formatting_py3.py
+++ b/tests/functional/s/string_formatting_py3.py
@@ -17,5 +17,5 @@ def issue_957_bad2():
def issue_957_uninferable():
- from butchery import meat
+ from butchery import meat # pylint: disable=import-outside-toplevel
print('%s%s%s' % ('eggs', *meat))
diff --git a/tests/functional/u/unbalanced_tuple_unpacking.py b/tests/functional/u/unbalanced_tuple_unpacking.py
index d3887f4f3..ed807c0d7 100644
--- a/tests/functional/u/unbalanced_tuple_unpacking.py
+++ b/tests/functional/u/unbalanced_tuple_unpacking.py
@@ -2,7 +2,7 @@
from __future__ import absolute_import
from functional.u.unpacking import unpack
-# pylint: disable=using-constant-test, useless-object-inheritance
+# pylint: disable=using-constant-test, useless-object-inheritance,import-outside-toplevel
def do_stuff():
"""This is not right."""
diff --git a/tests/input/func_w0401_disabled_in_func.py b/tests/input/func_w0401_disabled_in_func.py
index b9b0ced8d..69f266863 100644
--- a/tests/input/func_w0401_disabled_in_func.py
+++ b/tests/input/func_w0401_disabled_in_func.py
@@ -1,6 +1,6 @@
"""Test disabling of cyclic import check inside a function
"""
-# pylint: disable=no-absolute-import
+# pylint: disable=no-absolute-import,import-outside-toplevel
from __future__ import print_function