diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/whatsnew/2.13.rst | 5 | ||||
-rw-r--r-- | pylint/checkers/imports.py | 8 | ||||
-rw-r--r-- | tests/functional/u/ungrouped_imports_suppression.py | 15 | ||||
-rw-r--r-- | tests/functional/u/ungrouped_imports_suppression.txt | 2 |
5 files changed, 31 insertions, 4 deletions
@@ -76,6 +76,11 @@ Release date: TBA Closes #5025 +* Fixed an issue where ``ungrouped-imports`` could not be disabled without raising + ``useless-suppression``. + + Ref #2366 + * Added several checkers to deal with unicode security issues (see `Trojan Sources <https://trojansource.codes/>`_ and `PEP 672 <https://www.python.org/dev/peps/pep-0672/>`_ for details) that also diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index 2314725da..3c3f088ea 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -216,6 +216,11 @@ Other Changes Closes #5713 +* Fixed an issue where ``ungrouped-imports`` could not be disabled without raising + ``useless-suppression``. + + Ref #2366 + * Fixed a crash on ``__init__`` nodes when the attribute was previously uninferable due to a cache limit size. This limit can be hit when the inheritance pattern of a class (and therefore of the ``__init__`` attribute) is very large. diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index bcad7692e..689573b21 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -537,10 +537,6 @@ class ImportsChecker(DeprecatedMixin, BaseChecker): met_from: Set[str] = set() # set for 'from x import y' style current_package = None for import_node, import_name in std_imports + ext_imports + loc_imports: - if not self.linter.is_message_enabled( - "ungrouped-imports", import_node.fromlineno - ): - continue met = met_from if isinstance(import_node, nodes.ImportFrom) else met_import package, _, _ = import_name.partition(".") if ( @@ -551,6 +547,10 @@ class ImportsChecker(DeprecatedMixin, BaseChecker): ): self.add_message("ungrouped-imports", node=import_node, args=package) current_package = package + if not self.linter.is_message_enabled( + "ungrouped-imports", import_node.fromlineno + ): + continue met.add(package) self._imports_stack = [] diff --git a/tests/functional/u/ungrouped_imports_suppression.py b/tests/functional/u/ungrouped_imports_suppression.py new file mode 100644 index 000000000..9b482b355 --- /dev/null +++ b/tests/functional/u/ungrouped_imports_suppression.py @@ -0,0 +1,15 @@ +"""Check ungrouped import and interaction with useless-suppression. + +Previously disabling ungrouped-imports would always lead to useless-suppression. +""" +# pylint: enable=useless-suppression +# pylint: disable=unused-import, wrong-import-order + +import logging.config +import os.path +from astroid import are_exclusive # pylint: disable=ungrouped-imports # [useless-suppression] +import logging.handlers # pylint: disable=ungrouped-imports # This should not raise useless-suppression +try: + import os # [ungrouped-imports] +except ImportError: + pass diff --git a/tests/functional/u/ungrouped_imports_suppression.txt b/tests/functional/u/ungrouped_imports_suppression.txt new file mode 100644 index 000000000..3ba8b0ea0 --- /dev/null +++ b/tests/functional/u/ungrouped_imports_suppression.txt @@ -0,0 +1,2 @@ +useless-suppression:10:0:None:None::Useless suppression of 'ungrouped-imports':UNDEFINED +ungrouped-imports:13:4:13:13::Imports from package os are not grouped:UNDEFINED |