From 84ab8b11f958d4eec0a4b092267a09742a960785 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 9 Mar 2019 09:05:14 +0100 Subject: [PATCH 1/9] Feat - Add isort in the pre-commit configuration This is compatible with the current black configuration. See : https://github.com/ambv/black/issues/127 --- .isort.cfg | 7 +++++++ .pre-commit-config.yaml | 4 ++++ 2 files changed, 11 insertions(+) create mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000000..08417f7750 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,7 @@ +[settings] +multi_line_output=3 +line_length=88 +known_third_party=astroid, sphinx, isort, pytest, mccabe, six, +include_trailing_comma=True +skip_glob=*/functional/**,*/input/**,*/test/extension/**,*/test/regrtest_data/**,*/test/data/** +project=pylint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c750f005a..27ded48b92 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,7 @@ repos: hooks: - id: trailing-whitespace - id: end-of-file-fixer +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.13 + hooks: + - id: isort From f69341f3ffcf79ecabb13f3a49083137039137bb Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 9 Mar 2019 09:07:44 +0100 Subject: [PATCH 2/9] Chore - Update black and pre-commit in configuration --- .pre-commit-config.yaml | 4 ++-- tox.ini | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 27ded48b92..1e553c91cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ repos: - repo: https://github.com/ambv/black - rev: 18.6b4 + rev: 18.9b0 hooks: - id: black args: [--safe, --quiet] exclude: functional|input|test/extension|test/regrtest_data|test/data python_version: python3.6 - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v1.2.3 + rev: v2.1.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer diff --git a/tox.ini b/tox.ini index d847ac7673..c6ee64354a 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,7 @@ commands = pylint -rn --rcfile={toxinidir}/pylintrc --load-plugins=pylint.extens [testenv:formatting] basepython = python3 -deps = black==18.6b4 +deps = black==18.9b0 commands = black --check --exclude "functional|input|test/extension|test/regrtest_data|test/data" pylint changedir = {toxinidir} From cf7648479f783f41b23c12531fb928a64f0b8f03 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 9 Mar 2019 11:22:36 +0100 Subject: [PATCH 3/9] Style - Apply isort on all apllicable files --- bin/epylint | 1 + bin/pylint | 1 + bin/pyreverse | 1 + bin/symilar | 1 + doc/conf.py | 15 ++++----- doc/exts/pylint_extensions.py | 1 - doc/exts/pylint_features.py | 1 + examples/custom.py | 2 +- examples/custom_raw.py | 4 +-- pylint/checkers/__init__.py | 2 +- pylint/checkers/async.py | 7 ++--- pylint/checkers/base.py | 9 ++---- pylint/checkers/classes.py | 31 +++++++++---------- pylint/checkers/design_analysis.py | 10 +++--- pylint/checkers/exceptions.py | 3 +- pylint/checkers/format.py | 4 +-- pylint/checkers/imports.py | 18 +++++------ pylint/checkers/logging.py | 4 +-- pylint/checkers/misc.py | 7 ++--- pylint/checkers/newstyle.py | 4 +-- pylint/checkers/python3.py | 9 +++--- pylint/checkers/raw_metrics.py | 4 +-- pylint/checkers/refactoring.py | 7 ++--- pylint/checkers/similar.py | 5 +-- pylint/checkers/spelling.py | 9 +++--- pylint/checkers/stdlib.py | 5 ++- pylint/checkers/strings.py | 8 ++--- pylint/checkers/typecheck.py | 29 ++++++++--------- pylint/checkers/utils.py | 10 +++--- pylint/checkers/variables.py | 16 ++++------ pylint/config.py | 22 +++++++------ pylint/epylint.py | 4 +-- pylint/extensions/bad_builtin.py | 2 +- pylint/extensions/check_elif.py | 3 +- pylint/extensions/comparetozero.py | 3 +- pylint/extensions/docparams.py | 6 ++-- pylint/extensions/docstyle.py | 2 +- pylint/extensions/emptystring.py | 3 +- pylint/extensions/mccabe.py | 7 ++--- pylint/extensions/overlapping_exceptions.py | 4 +-- pylint/extensions/redefined_variable_type.py | 2 +- pylint/graph.py | 4 +-- pylint/lint.py | 26 +++++++--------- pylint/message/__init__.py | 4 +-- pylint/message/message_handler_mix_in.py | 4 +-- pylint/pyreverse/diadefslib.py | 2 +- pylint/pyreverse/diagrams.py | 3 +- pylint/pyreverse/inspector.py | 7 +---- pylint/pyreverse/main.py | 4 +-- pylint/pyreverse/writer.py | 2 +- pylint/reporters/__init__.py | 3 +- pylint/reporters/text.py | 5 ++- pylint/reporters/ureports/__init__.py | 1 - pylint/reporters/ureports/text_writer.py | 1 - pylint/test/conftest.py | 2 +- pylint/test/extensions/data/docstring.py | 1 + pylint/test/extensions/test_bad_builtin.py | 1 - pylint/test/extensions/test_check_docs.py | 7 ++--- .../test/extensions/test_check_docs_utils.py | 5 ++- .../test/extensions/test_check_raise_docs.py | 4 +-- .../test/extensions/test_check_return_docs.py | 4 +-- .../test/extensions/test_check_yields_docs.py | 4 +-- pylint/test/extensions/test_docstyle.py | 1 - pylint/test/extensions/test_emptystring.py | 1 + .../extensions/test_overlapping_exceptions.py | 6 ++-- pylint/test/extensions/test_redefined.py | 1 - pylint/test/test_func.py | 4 +-- pylint/test/test_functional.py | 11 +++---- pylint/test/test_import_graph.py | 5 ++- pylint/test/test_regr.py | 5 ++- pylint/test/test_self.py | 15 ++++----- pylint/test/unittest_checker_base.py | 1 + pylint/test/unittest_checker_classes.py | 1 + pylint/test/unittest_checker_format.py | 9 ++---- pylint/test/unittest_checker_imports.py | 3 +- pylint/test/unittest_checker_misc.py | 2 +- pylint/test/unittest_checker_python3.py | 6 ++-- pylint/test/unittest_checker_similar.py | 4 +-- pylint/test/unittest_checker_spelling.py | 5 ++- pylint/test/unittest_checker_stdlib.py | 2 +- pylint/test/unittest_checker_strings.py | 1 - pylint/test/unittest_checker_typecheck.py | 3 +- pylint/test/unittest_checker_variables.py | 4 +-- pylint/test/unittest_checkers_utils.py | 2 +- pylint/test/unittest_config.py | 2 +- pylint/test/unittest_pyreverse_diadefs.py | 6 ++-- pylint/test/unittest_pyreverse_inspector.py | 6 ++-- pylint/test/unittest_pyreverse_writer.py | 7 ++--- pylint/test/unittest_reporters_json.py | 3 +- pylint/test/unittest_reporting.py | 8 ++--- pylint/test/utils/unittest_utils.py | 2 +- pylint/testutils.py | 12 +++---- pylint/utils/__init__.py | 2 +- pylint/utils/file_state.py | 1 + pylint/utils/utils.py | 3 +- setup.py | 10 +++--- 96 files changed, 245 insertions(+), 289 deletions(-) diff --git a/bin/epylint b/bin/epylint index 4aad65703b..a55adf4c3e 100755 --- a/bin/epylint +++ b/bin/epylint @@ -1,3 +1,4 @@ #!/usr/bin/env python from pylint import epylint + epylint.Run() diff --git a/bin/pylint b/bin/pylint index e3e520f0c7..162e96d407 100755 --- a/bin/pylint +++ b/bin/pylint @@ -1,3 +1,4 @@ #!/usr/bin/env python from pylint import run_pylint + run_pylint() diff --git a/bin/pyreverse b/bin/pyreverse index 71269e769f..d0b080dfc2 100755 --- a/bin/pyreverse +++ b/bin/pyreverse @@ -1,3 +1,4 @@ #!/usr/bin/env python from pylint import run_pyreverse + run_pyreverse() diff --git a/bin/symilar b/bin/symilar index ef94462473..7125d1f91c 100755 --- a/bin/symilar +++ b/bin/symilar @@ -1,3 +1,4 @@ #!/usr/bin/env python from pylint import run_symilar + run_symilar() diff --git a/doc/conf.py b/doc/conf.py index ada9ec4933..16bfb7eb9f 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -11,10 +11,17 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os +import sys from datetime import datetime +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +from pylint.__pkginfo__ import version + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -51,12 +58,6 @@ current_year = datetime.utcnow().year copyright = '2003-{year}, Logilab, PyCQA and contributors'.format(year=current_year) -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. -from pylint.__pkginfo__ import version # The full version, including alpha/beta/rc tags. release = version diff --git a/doc/exts/pylint_extensions.py b/doc/exts/pylint_extensions.py index e6b1eb46f1..2e1d821635 100755 --- a/doc/exts/pylint_extensions.py +++ b/doc/exts/pylint_extensions.py @@ -13,7 +13,6 @@ from pylint.lint import PyLinter - # Some modules have been renamed and deprecated under their old names. # Skip documenting these modules since: # 1) They are deprecated, why document them moving forward? diff --git a/doc/exts/pylint_features.py b/doc/exts/pylint_features.py index fcb2d10e1e..2ff0e52a76 100755 --- a/doc/exts/pylint_features.py +++ b/doc/exts/pylint_features.py @@ -11,6 +11,7 @@ from pylint.lint import PyLinter + def builder_inited(app): # PACKAGE/docs/exts/pylint_extensions.py --> PACKAGE/ base_path = os.path.dirname( diff --git a/examples/custom.py b/examples/custom.py index 54c2937b10..039b018b8b 100644 --- a/examples/custom.py +++ b/examples/custom.py @@ -1,7 +1,7 @@ import astroid -from pylint.interfaces import IAstroidChecker from pylint.checkers import BaseChecker +from pylint.interfaces import IAstroidChecker # This is our checker class. diff --git a/examples/custom_raw.py b/examples/custom_raw.py index a866667244..fb28d49311 100644 --- a/examples/custom_raw.py +++ b/examples/custom_raw.py @@ -1,5 +1,6 @@ -from pylint.interfaces import IRawChecker from pylint.checkers import BaseChecker +from pylint.interfaces import IRawChecker + class MyRawChecker(BaseChecker): """check for line continuations with '\' instead of using triple @@ -31,4 +32,3 @@ def process_module(self, node): def register(linter): """required method to auto register this checker""" linter.register_checker(MyRawChecker(linter)) - diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py index 1a4c0009f1..f745037bc1 100644 --- a/pylint/checkers/__init__.py +++ b/pylint/checkers/__init__.py @@ -45,9 +45,9 @@ from typing import Any from pylint.config import OptionsProviderMixIn +from pylint.interfaces import UNDEFINED from pylint.reporters import diff_string from pylint.utils import register_plugins -from pylint.interfaces import UNDEFINED def table_lines_from_stats(stats, old_stats, columns): diff --git a/pylint/checkers/async.py b/pylint/checkers/async.py index 21feba0355..c33071e84b 100644 --- a/pylint/checkers/async.py +++ b/pylint/checkers/async.py @@ -9,13 +9,10 @@ import sys import astroid -from astroid import bases -from astroid import exceptions +from astroid import bases, exceptions -from pylint import checkers +from pylint import checkers, interfaces, utils from pylint.checkers import utils as checker_utils -from pylint import interfaces -from pylint import utils from pylint.checkers.utils import decorated_with diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index e2e35f3dd4..bce4ae7fd3 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -40,22 +40,19 @@ import builtins import collections import itertools -import sys import re +import sys from typing import Pattern import astroid import astroid.bases import astroid.scoped_nodes -from pylint import checkers -from pylint import exceptions -from pylint import interfaces +import pylint.utils as lint_utils +from pylint import checkers, exceptions, interfaces, reporters from pylint.checkers import utils -from pylint import reporters from pylint.checkers.utils import get_node_last_lineno from pylint.reporters.ureports import nodes as reporter_nodes -import pylint.utils as lint_utils class NamingStyle: diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 543b27ecf7..d75107136c 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -32,38 +32,37 @@ from __future__ import generators import collections -from itertools import chain, zip_longest import sys +from itertools import chain, zip_longest import astroid -from astroid.bases import Generator, BUILTINS -from astroid.exceptions import InconsistentMroError, DuplicateBasesError -from astroid import decorators -from astroid import objects +from astroid import decorators, objects +from astroid.bases import BUILTINS, Generator +from astroid.exceptions import DuplicateBasesError, InconsistentMroError from astroid.scoped_nodes import function_to_method -from pylint.interfaces import IAstroidChecker + from pylint.checkers import BaseChecker from pylint.checkers.utils import ( PYMETHODS, SPECIAL_METHODS_PARAMS, - overrides_a_method, check_messages, + class_is_abstract, + decorated_with, + decorated_with_property, + has_known_bases, is_attr_private, is_attr_protected, - node_frame_class, is_builtin_object, - decorated_with_property, - unimplemented_abstract_methods, - decorated_with, - class_is_abstract, - safe_infer, - has_known_bases, - is_iterable, is_comprehension, + is_iterable, + node_frame_class, + overrides_a_method, + safe_infer, + unimplemented_abstract_methods, ) +from pylint.interfaces import IAstroidChecker from pylint.utils import get_global_option - if sys.version_info >= (3, 0): NEXT_METHOD = "__next__" else: diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py index e9f0a04707..b6fd9913ce 100644 --- a/pylint/checkers/design_analysis.py +++ b/pylint/checkers/design_analysis.py @@ -17,18 +17,16 @@ """check for signs of poor design""" -from collections import defaultdict import re +from collections import defaultdict import astroid -from astroid import If, BoolOp -from astroid import decorators +from astroid import BoolOp, If, decorators -from pylint.interfaces import IAstroidChecker +from pylint import utils from pylint.checkers import BaseChecker from pylint.checkers.utils import check_messages -from pylint import utils - +from pylint.interfaces import IAstroidChecker MSGS = { "R0901": ( diff --git a/pylint/checkers/exceptions.py b/pylint/checkers/exceptions.py index c43af53af3..6521a5bd50 100644 --- a/pylint/checkers/exceptions.py +++ b/pylint/checkers/exceptions.py @@ -29,9 +29,8 @@ import astroid -from pylint import checkers +from pylint import checkers, interfaces from pylint.checkers import utils -from pylint import interfaces def _builtin_exceptions(): diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index d1aa8e91bc..84b6b273ea 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -50,10 +50,10 @@ from astroid import nodes -from pylint.interfaces import ITokenChecker, IAstroidChecker, IRawChecker from pylint.checkers import BaseTokenChecker from pylint.checkers.utils import check_messages -from pylint.utils import WarningScope, OPTION_RGX +from pylint.interfaces import IAstroidChecker, IRawChecker, ITokenChecker +from pylint.utils import OPTION_RGX, WarningScope _ASYNC_TOKEN = "async" _CONTINUATION_BLOCK_OPENERS = [ diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index 07ae01fec7..82ef94a079 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -30,27 +30,27 @@ """imports checkers for Python code""" import collections -from distutils import sysconfig +import copy import os import sys -import copy +from distutils import sysconfig import astroid +import isort from astroid import are_exclusive, decorators from astroid.modutils import get_module_part, is_standard_module -import isort -from pylint.interfaces import IAstroidChecker -from pylint.utils import get_global_option -from pylint.exceptions import EmptyReportError from pylint.checkers import BaseChecker from pylint.checkers.utils import ( check_messages, - node_ignores_exception, is_from_fallback_block, + node_ignores_exception, ) -from pylint.graph import get_cycles, DotBackend -from pylint.reporters.ureports.nodes import VerbatimText, Paragraph +from pylint.exceptions import EmptyReportError +from pylint.graph import DotBackend, get_cycles +from pylint.interfaces import IAstroidChecker +from pylint.reporters.ureports.nodes import Paragraph, VerbatimText +from pylint.utils import get_global_option def _qualified_names(modname): diff --git a/pylint/checkers/logging.py b/pylint/checkers/logging.py index 13646cdcef..7d8dd5b69b 100644 --- a/pylint/checkers/logging.py +++ b/pylint/checkers/logging.py @@ -21,12 +21,10 @@ import astroid -from pylint import checkers -from pylint import interfaces +from pylint import checkers, interfaces from pylint.checkers import utils from pylint.checkers.utils import check_messages - MSGS = { "W1201": ( "Specify string format arguments as logging function parameters", diff --git a/pylint/checkers/misc.py b/pylint/checkers/misc.py index 26dc0a3df0..d12c2639e5 100644 --- a/pylint/checkers/misc.py +++ b/pylint/checkers/misc.py @@ -20,14 +20,13 @@ # pylint: disable=W0511 -import tokenize - import re +import tokenize -from pylint.interfaces import IRawChecker, ITokenChecker from pylint.checkers import BaseChecker -from pylint.utils import OPTION_RGX +from pylint.interfaces import IRawChecker, ITokenChecker from pylint.message import MessagesHandlerMixIn +from pylint.utils import OPTION_RGX class ByIdManagedMessagesChecker(BaseChecker): diff --git a/pylint/checkers/newstyle.py b/pylint/checkers/newstyle.py index 89d31653be..97e2fcb655 100644 --- a/pylint/checkers/newstyle.py +++ b/pylint/checkers/newstyle.py @@ -17,9 +17,9 @@ import astroid -from pylint.interfaces import IAstroidChecker from pylint.checkers import BaseChecker -from pylint.checkers.utils import check_messages, node_frame_class, has_known_bases +from pylint.checkers.utils import check_messages, has_known_bases, node_frame_class +from pylint.interfaces import IAstroidChecker MSGS = { "E1003": ( diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index d577c918c6..43025d0c8b 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -26,21 +26,20 @@ """Check Python 2 code for Python 2/3 source-compatible issues.""" from __future__ import absolute_import, print_function -from collections import namedtuple import re import sys import tokenize +from collections import namedtuple from typing import FrozenSet import astroid from astroid import bases from pylint import checkers, interfaces -from pylint.checkers.utils import node_ignores_exception, find_try_except_wrapper_node -from pylint.interfaces import INFERENCE_FAILURE, INFERENCE -from pylint.utils import WarningScope from pylint.checkers import utils - +from pylint.checkers.utils import find_try_except_wrapper_node, node_ignores_exception +from pylint.interfaces import INFERENCE, INFERENCE_FAILURE +from pylint.utils import WarningScope _ZERO = re.compile("^0+$") diff --git a/pylint/checkers/raw_metrics.py b/pylint/checkers/raw_metrics.py index 7ab165675c..49ee2fa2f3 100644 --- a/pylint/checkers/raw_metrics.py +++ b/pylint/checkers/raw_metrics.py @@ -18,9 +18,9 @@ import tokenize from typing import Any -from pylint.interfaces import ITokenChecker -from pylint.exceptions import EmptyReportError from pylint.checkers import BaseTokenChecker +from pylint.exceptions import EmptyReportError +from pylint.interfaces import ITokenChecker from pylint.reporters import diff_string from pylint.reporters.ureports.nodes import Table diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py index 6a349c0677..cab521aaac 100644 --- a/pylint/checkers/refactoring.py +++ b/pylint/checkers/refactoring.py @@ -22,21 +22,18 @@ """Looks for code which can be refactored.""" import builtins -from functools import reduce - import collections import itertools import tokenize +from functools import reduce import astroid from astroid import decorators -from pylint import interfaces -from pylint import checkers +from pylint import checkers, interfaces from pylint import utils as lint_utils from pylint.checkers import utils - KNOWN_INFINITE_ITERATORS = {"itertools.count"} diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index 2e45ce9c68..d79785d667 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -18,16 +18,17 @@ """ from __future__ import print_function + import sys from collections import defaultdict from itertools import groupby import astroid -from pylint.utils import decoding_stream -from pylint.interfaces import IRawChecker from pylint.checkers import BaseChecker, table_lines_from_stats +from pylint.interfaces import IRawChecker from pylint.reporters.ureports.nodes import Table +from pylint.utils import decoding_stream class Similar: diff --git a/pylint/checkers/spelling.py b/pylint/checkers/spelling.py index df99f6b3e1..f1952e89fc 100644 --- a/pylint/checkers/spelling.py +++ b/pylint/checkers/spelling.py @@ -19,8 +19,12 @@ """ import os -import tokenize import re +import tokenize + +from pylint.checkers import BaseTokenChecker +from pylint.checkers.utils import check_messages +from pylint.interfaces import IAstroidChecker, ITokenChecker try: import enchant @@ -43,9 +47,6 @@ class Chunker: # type: ignore pass -from pylint.interfaces import ITokenChecker, IAstroidChecker -from pylint.checkers import BaseTokenChecker -from pylint.checkers.utils import check_messages if enchant is not None: br = enchant.Broker() diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py index 7dad31d287..778ea98df2 100644 --- a/pylint/checkers/stdlib.py +++ b/pylint/checkers/stdlib.py @@ -26,10 +26,9 @@ import astroid from astroid.bases import Instance from astroid.node_classes import Const -from pylint.interfaces import IAstroidChecker -from pylint.checkers import BaseChecker -from pylint.checkers import utils +from pylint.checkers import BaseChecker, utils +from pylint.interfaces import IAstroidChecker OPEN_FILES = {"open", "file"} UNITTEST_CASE = "unittest.case" diff --git a/pylint/checkers/strings.py b/pylint/checkers/strings.py index d7caf85a14..9b22e5244c 100644 --- a/pylint/checkers/strings.py +++ b/pylint/checkers/strings.py @@ -23,18 +23,18 @@ """ import builtins +import numbers import sys import tokenize -import numbers from collections import Counter import astroid from astroid.arguments import CallSite from astroid.node_classes import Const -from pylint.interfaces import ITokenChecker, IAstroidChecker, IRawChecker -from pylint.checkers import BaseChecker, BaseTokenChecker -from pylint.checkers import utils + +from pylint.checkers import BaseChecker, BaseTokenChecker, utils from pylint.checkers.utils import check_messages +from pylint.interfaces import IAstroidChecker, IRawChecker, ITokenChecker _AST_NODE_STR_TYPES = ("__builtin__.unicode", "__builtin__.str", "builtins.str") diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 417662b877..fa95d7cc4a 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -47,35 +47,32 @@ from functools import singledispatch import astroid -import astroid.context import astroid.arguments +import astroid.context import astroid.nodes -from astroid import exceptions, decorators +from astroid import bases, decorators, exceptions, modutils, objects from astroid.interpreter import dunder_lookup -from astroid import objects -from astroid import bases -from astroid import modutils -from pylint.interfaces import IAstroidChecker, INFERENCE from pylint.checkers import BaseChecker from pylint.checkers.utils import ( - is_super, check_messages, - decorated_with_property, decorated_with, - node_ignores_exception, - is_iterable, - is_mapping, - supports_membership_test, + decorated_with_property, + has_known_bases, + is_builtin_object, is_comprehension, is_inside_abstract_class, + is_iterable, + is_mapping, + is_super, + node_ignores_exception, + safe_infer, + supports_delitem, supports_getitem, + supports_membership_test, supports_setitem, - supports_delitem, - safe_infer, - has_known_bases, - is_builtin_object, ) +from pylint.interfaces import INFERENCE, IAstroidChecker from pylint.utils import get_global_option BUILTINS = builtins.__name__ diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index dbbba49b0e..38dca2a386 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -30,20 +30,20 @@ """some functions that may be useful for various checkers """ import builtins -from functools import lru_cache, partial import itertools import numbers import re -import sys import string -from typing import Optional, Iterable, Tuple, Callable, Set, Union, Match, Dict, List -import _string # pylint: disable=wrong-import-position, wrong-import-order +import sys +from functools import lru_cache, partial +from typing import Callable, Dict, Iterable, List, Match, Optional, Set, Tuple, Union import astroid -from astroid.exceptions import _NonDeducibleTypeHierarchy from astroid import bases as _bases from astroid import scoped_nodes +from astroid.exceptions import _NonDeducibleTypeHierarchy +import _string # pylint: disable=wrong-import-position, wrong-import-order BUILTINS_NAME = builtins.__name__ COMP_NODE_TYPES = ( diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 85de92aaa1..02974a19a1 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -34,26 +34,22 @@ """variables checkers for Python code """ +import collections import copy -from functools import lru_cache import itertools -import collections import os -import sys import re +import sys +from functools import lru_cache import astroid -from astroid import decorators -from astroid import modutils -from astroid import objects +from astroid import decorators, modutils, objects from astroid.context import InferenceContext +from pylint.checkers import BaseChecker, utils from pylint.checkers.utils import is_postponed_evaluation_enabled -from pylint.interfaces import IAstroidChecker, INFERENCE, INFERENCE_FAILURE, HIGH +from pylint.interfaces import HIGH, INFERENCE, INFERENCE_FAILURE, IAstroidChecker from pylint.utils import get_global_option -from pylint.checkers import BaseChecker -from pylint.checkers import utils - SPECIAL_OBJ = re.compile("^_{2}[a-z]+_{2}$") FUTURE = "__future__" diff --git a/pylint/config.py b/pylint/config.py index 0477c7914f..a913f86199 100644 --- a/pylint/config.py +++ b/pylint/config.py @@ -35,15 +35,9 @@ """ from __future__ import print_function -# TODO(cpopa): this module contains the logic for the -# configuration parser and for the command line parser, -# but it's really coupled to optparse's internals. -# The code was copied almost verbatim from logilab.common, -# in order to not depend on it anymore and it will definitely -# need a cleanup. It could be completely reengineered as well. - -import contextlib import collections +import configparser +import contextlib import copy import io import optparse @@ -53,10 +47,18 @@ import sys import time -import configparser - from pylint import utils +# TODO(cpopa): this module contains the logic for the +# configuration parser and for the command line parser, +# but it's really coupled to optparse's internals. +# The code was copied almost verbatim from logilab.common, +# in order to not depend on it anymore and it will definitely +# need a cleanup. It could be completely reengineered as well. + + + + USER_HOME = os.path.expanduser("~") if "PYLINTHOME" in os.environ: diff --git a/pylint/epylint.py b/pylint/epylint.py index 50c3a99f9c..c2d4a21d8c 100755 --- a/pylint/epylint.py +++ b/pylint/epylint.py @@ -56,10 +56,10 @@ import os import os.path as osp -import sys import shlex -from subprocess import Popen, PIPE +import sys from io import StringIO +from subprocess import PIPE, Popen def _get_env(): diff --git a/pylint/extensions/bad_builtin.py b/pylint/extensions/bad_builtin.py index 2609d3168f..f5533b8362 100644 --- a/pylint/extensions/bad_builtin.py +++ b/pylint/extensions/bad_builtin.py @@ -7,11 +7,11 @@ import sys import astroid + from pylint.checkers import BaseChecker from pylint.checkers.utils import check_messages from pylint.interfaces import IAstroidChecker - BAD_FUNCTIONS = ["map", "filter"] if sys.version_info < (3, 0): BAD_FUNCTIONS.append("input") diff --git a/pylint/extensions/check_elif.py b/pylint/extensions/check_elif.py index 9ef0b3fa33..67555b16ad 100644 --- a/pylint/extensions/check_elif.py +++ b/pylint/extensions/check_elif.py @@ -8,9 +8,10 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING import astroid + from pylint.checkers import BaseTokenChecker from pylint.checkers.utils import check_messages -from pylint.interfaces import ITokenChecker, IAstroidChecker +from pylint.interfaces import IAstroidChecker, ITokenChecker class ElseifUsedChecker(BaseTokenChecker): diff --git a/pylint/extensions/comparetozero.py b/pylint/extensions/comparetozero.py index 92063ab180..e31f488751 100644 --- a/pylint/extensions/comparetozero.py +++ b/pylint/extensions/comparetozero.py @@ -11,8 +11,7 @@ import astroid -from pylint import interfaces -from pylint import checkers +from pylint import checkers, interfaces from pylint.checkers import utils diff --git a/pylint/extensions/docparams.py b/pylint/extensions/docparams.py index 771d64c04a..939e2a3fa5 100644 --- a/pylint/extensions/docparams.py +++ b/pylint/extensions/docparams.py @@ -16,14 +16,14 @@ """Pylint plugin for checking in Sphinx, Google, or Numpy style docstrings """ -from __future__ import print_function, division, absolute_import +from __future__ import absolute_import, division, print_function import astroid -from pylint.interfaces import IAstroidChecker +import pylint.extensions._check_docs_utils as utils from pylint.checkers import BaseChecker from pylint.checkers import utils as checker_utils -import pylint.extensions._check_docs_utils as utils +from pylint.interfaces import IAstroidChecker class DocstringParameterChecker(BaseChecker): diff --git a/pylint/extensions/docstyle.py b/pylint/extensions/docstyle.py index 1f50a414ee..36f506fcf4 100644 --- a/pylint/extensions/docstyle.py +++ b/pylint/extensions/docstyle.py @@ -9,8 +9,8 @@ import linecache from pylint import checkers -from pylint.interfaces import IAstroidChecker, HIGH from pylint.checkers.utils import check_messages +from pylint.interfaces import HIGH, IAstroidChecker class DocStringStyleChecker(checkers.BaseChecker): diff --git a/pylint/extensions/emptystring.py b/pylint/extensions/emptystring.py index ddca8f7d5e..04021d5046 100644 --- a/pylint/extensions/emptystring.py +++ b/pylint/extensions/emptystring.py @@ -11,8 +11,7 @@ import astroid -from pylint import interfaces -from pylint import checkers +from pylint import checkers, interfaces from pylint.checkers import utils diff --git a/pylint/extensions/mccabe.py b/pylint/extensions/mccabe.py index 41eca280fc..69bc1775ba 100644 --- a/pylint/extensions/mccabe.py +++ b/pylint/extensions/mccabe.py @@ -9,10 +9,9 @@ from __future__ import absolute_import -from mccabe import ( - PathGraph as Mccabe_PathGraph, - PathGraphingAstVisitor as Mccabe_PathGraphingAstVisitor, -) +from mccabe import PathGraph as Mccabe_PathGraph +from mccabe import PathGraphingAstVisitor as Mccabe_PathGraphingAstVisitor + from pylint import checkers from pylint.checkers.utils import check_messages from pylint.interfaces import HIGH, IAstroidChecker diff --git a/pylint/extensions/overlapping_exceptions.py b/pylint/extensions/overlapping_exceptions.py index 3b1454cae0..be2208c9b1 100644 --- a/pylint/extensions/overlapping_exceptions.py +++ b/pylint/extensions/overlapping_exceptions.py @@ -7,10 +7,8 @@ import astroid -from pylint import interfaces -from pylint import checkers +from pylint import checkers, interfaces from pylint.checkers import utils - from pylint.checkers.exceptions import _annotated_unpack_infer diff --git a/pylint/extensions/redefined_variable_type.py b/pylint/extensions/redefined_variable_type.py index a58f04e2d1..cfe4754c94 100644 --- a/pylint/extensions/redefined_variable_type.py +++ b/pylint/extensions/redefined_variable_type.py @@ -8,11 +8,11 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING import astroid + from pylint.checkers import BaseChecker from pylint.checkers.utils import check_messages, is_none, node_type from pylint.interfaces import IAstroidChecker - BUILTINS = "builtins" diff --git a/pylint/graph.py b/pylint/graph.py index f7790dae8f..3eb4802275 100644 --- a/pylint/graph.py +++ b/pylint/graph.py @@ -11,11 +11,11 @@ (dot generation adapted from pypy/translator/tool/make_dot.py) """ -import os.path as osp +import codecs import os +import os.path as osp import sys import tempfile -import codecs def target_info_from_filename(filename): diff --git a/pylint/lint.py b/pylint/lint.py index c012c0b296..d02410fa08 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -62,31 +62,29 @@ import collections import contextlib -from io import TextIOWrapper import operator import os - -try: - import multiprocessing -except ImportError: - multiprocessing = None # type: ignore import sys import tokenize import warnings +from io import TextIOWrapper import astroid +from astroid import modutils from astroid.__pkginfo__ import version as astroid_version from astroid.builder import AstroidBuilder -from astroid import modutils -from pylint import checkers -from pylint import interfaces -from pylint import reporters -from pylint.message import MessagesStore, Message, MSG_TYPES, MessagesHandlerMixIn -from pylint.utils import FileState, ASTWalker, ReportsHandlerMixIn, OPTION_RGX, utils -from pylint import exceptions -from pylint import config + +from pylint import checkers, config, exceptions, interfaces, reporters from pylint.__pkginfo__ import version +from pylint.message import MSG_TYPES, Message, MessagesHandlerMixIn, MessagesStore from pylint.reporters.ureports import nodes as report_nodes +from pylint.utils import OPTION_RGX, ASTWalker, FileState, ReportsHandlerMixIn, utils + +try: + import multiprocessing +except ImportError: + multiprocessing = None # type: ignore + MANAGER = astroid.MANAGER diff --git a/pylint/message/__init__.py b/pylint/message/__init__.py index 694e2eb136..4b71f57b9d 100644 --- a/pylint/message/__init__.py +++ b/pylint/message/__init__.py @@ -39,16 +39,16 @@ """All the classes related to Message handling.""" +from pylint.message.build_message_definition import build_message_def from pylint.message.constants import ( - MSG_STATE_CONFIDENCE, _SCOPE_EXEMPT, + MSG_STATE_CONFIDENCE, MSG_STATE_SCOPE_CONFIG, MSG_STATE_SCOPE_MODULE, MSG_TYPES, MSG_TYPES_LONG, MSG_TYPES_STATUS, ) -from pylint.message.build_message_definition import build_message_def from pylint.message.message import Message from pylint.message.message_definition import MessageDefinition from pylint.message.message_handler_mix_in import MessagesHandlerMixIn diff --git a/pylint/message/message_handler_mix_in.py b/pylint/message/message_handler_mix_in.py index d01be8ff3a..7336979c25 100644 --- a/pylint/message/message_handler_mix_in.py +++ b/pylint/message/message_handler_mix_in.py @@ -10,6 +10,7 @@ from pylint.exceptions import InvalidMessageError, UnknownMessageError from pylint.interfaces import UNDEFINED +from pylint.message.build_message_definition import build_message_def from pylint.message.constants import ( _MSG_ORDER, _SCOPE_EXEMPT, @@ -20,14 +21,13 @@ MSG_TYPES_STATUS, ) from pylint.message.message import Message -from pylint.utils.warning_scope import WarningScope -from pylint.message.build_message_definition import build_message_def from pylint.utils.utils import ( _format_option_value, category_id, get_module_and_frameid, normalize_text, ) +from pylint.utils.warning_scope import WarningScope def _rest_format_section(stream, section, options, doc=None): diff --git a/pylint/pyreverse/diadefslib.py b/pylint/pyreverse/diadefslib.py index e64614fc7e..de4e9fd4aa 100644 --- a/pylint/pyreverse/diadefslib.py +++ b/pylint/pyreverse/diadefslib.py @@ -19,7 +19,7 @@ import astroid -from pylint.pyreverse.diagrams import PackageDiagram, ClassDiagram +from pylint.pyreverse.diagrams import ClassDiagram, PackageDiagram from pylint.pyreverse.utils import LocalsVisitor BUILTINS_NAME = "builtins" diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index afd7ffee4f..b53b845c2b 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -12,8 +12,9 @@ """ import astroid -from pylint.pyreverse.utils import is_interface, FilterMixIn + from pylint.checkers.utils import decorated_with_property +from pylint.pyreverse.utils import FilterMixIn, is_interface class Figure: diff --git a/pylint/pyreverse/inspector.py b/pylint/pyreverse/inspector.py index eca4b67aa7..b4df388be4 100644 --- a/pylint/pyreverse/inspector.py +++ b/pylint/pyreverse/inspector.py @@ -18,12 +18,7 @@ import traceback import astroid -from astroid import bases -from astroid import exceptions -from astroid import manager -from astroid import modutils -from astroid import node_classes - +from astroid import bases, exceptions, manager, modutils, node_classes from pylint.pyreverse import utils diff --git a/pylint/pyreverse/main.py b/pylint/pyreverse/main.py index 2be7c486da..8d30eacbad 100644 --- a/pylint/pyreverse/main.py +++ b/pylint/pyreverse/main.py @@ -20,9 +20,9 @@ import sys from pylint.config import ConfigurationMixIn -from pylint.pyreverse.inspector import Linker, project_from_files -from pylint.pyreverse.diadefslib import DiadefsHandler from pylint.pyreverse import writer +from pylint.pyreverse.diadefslib import DiadefsHandler +from pylint.pyreverse.inspector import Linker, project_from_files from pylint.pyreverse.utils import insert_default_options OPTIONS = ( diff --git a/pylint/pyreverse/writer.py b/pylint/pyreverse/writer.py index c97ba9bf5e..609b1efcd3 100644 --- a/pylint/pyreverse/writer.py +++ b/pylint/pyreverse/writer.py @@ -13,9 +13,9 @@ """Utilities for creating VCG and Dot diagrams""" +from pylint.graph import DotBackend from pylint.pyreverse.utils import is_exception from pylint.pyreverse.vcgutils import VCGPrinter -from pylint.graph import DotBackend class DiagramWriter: diff --git a/pylint/reporters/__init__.py b/pylint/reporters/__init__.py index c09ebdd0c2..98b0364a22 100644 --- a/pylint/reporters/__init__.py +++ b/pylint/reporters/__init__.py @@ -19,12 +19,11 @@ """utilities methods and classes for reporters""" from __future__ import print_function -import sys import locale import os +import sys import warnings - CMPS = ["=", "-", "+"] # py3k has no more cmp builtin diff --git a/pylint/reporters/text.py b/pylint/reporters/text.py index 4c682ae05e..6af8706d0c 100644 --- a/pylint/reporters/text.py +++ b/pylint/reporters/text.py @@ -21,15 +21,14 @@ from __future__ import print_function import os -import warnings import sys +import warnings +from pylint import utils from pylint.interfaces import IReporter from pylint.reporters import BaseReporter -from pylint import utils from pylint.reporters.ureports.text_writer import TextWriter - TITLE_UNDERLINES = ["", "=", "-", "."] ANSI_PREFIX = "\033[" diff --git a/pylint/reporters/ureports/__init__.py b/pylint/reporters/ureports/__init__.py index 56a829facd..361552be78 100644 --- a/pylint/reporters/ureports/__init__.py +++ b/pylint/reporters/ureports/__init__.py @@ -13,7 +13,6 @@ """ import os import sys - from io import StringIO diff --git a/pylint/reporters/ureports/text_writer.py b/pylint/reporters/ureports/text_writer.py index 9d9e1ad342..acb6a9ac84 100644 --- a/pylint/reporters/ureports/text_writer.py +++ b/pylint/reporters/ureports/text_writer.py @@ -10,7 +10,6 @@ from pylint.reporters.ureports import BaseWriter - TITLE_UNDERLINES = ["", "=", "-", "`", ".", "~", "^"] BULLETS = ["*", "-"] diff --git a/pylint/test/conftest.py b/pylint/test/conftest.py index d75522bedc..985866893d 100644 --- a/pylint/test/conftest.py +++ b/pylint/test/conftest.py @@ -1,10 +1,10 @@ # pylint: disable=redefined-outer-name import os + import pytest from pylint import checkers from pylint.lint import PyLinter - # pylint: disable=no-name-in-module from pylint.testutils import MinimalTestReporter diff --git a/pylint/test/extensions/data/docstring.py b/pylint/test/extensions/data/docstring.py index 5410a9bb40..5a2c3fe63b 100644 --- a/pylint/test/extensions/data/docstring.py +++ b/pylint/test/extensions/data/docstring.py @@ -38,3 +38,4 @@ def method6(self): def method7(self): u"""Test OK 3 with unicode string""" + diff --git a/pylint/test/extensions/test_bad_builtin.py b/pylint/test/extensions/test_bad_builtin.py index 7d5d7f3045..2fd8a95e61 100644 --- a/pylint/test/extensions/test_bad_builtin.py +++ b/pylint/test/extensions/test_bad_builtin.py @@ -14,7 +14,6 @@ from pylint.extensions.bad_builtin import BadBuiltinChecker from pylint.lint import fix_import_path - EXPECTED = [ "Used builtin function 'map'. Using a list comprehension can be clearer.", "Used builtin function 'filter'. Using a list comprehension can be clearer.", diff --git a/pylint/test/extensions/test_check_docs.py b/pylint/test/extensions/test_check_docs.py index bad6baf077..63825c415f 100644 --- a/pylint/test/extensions/test_check_docs.py +++ b/pylint/test/extensions/test_check_docs.py @@ -16,16 +16,15 @@ """Unit tests for the pylint checkers in :mod:`pylint.extensions.check_docs`, in particular the parameter documentation checker `DocstringChecker` """ -from __future__ import division, print_function, absolute_import +from __future__ import absolute_import, division, print_function import sys -import pytest - import astroid -from pylint.testutils import CheckerTestCase, Message, set_config +import pytest from pylint.extensions.docparams import DocstringParameterChecker +from pylint.testutils import CheckerTestCase, Message, set_config class TestParamDocChecker(CheckerTestCase): diff --git a/pylint/test/extensions/test_check_docs_utils.py b/pylint/test/extensions/test_check_docs_utils.py index 28c9a05912..26af9db9d0 100644 --- a/pylint/test/extensions/test_check_docs_utils.py +++ b/pylint/test/extensions/test_check_docs_utils.py @@ -9,11 +9,10 @@ """Unit tests for the pylint checkers in :mod:`pylint.extensions.check_docs`, in particular the parameter documentation checker `DocstringChecker` """ -from __future__ import division, print_function, absolute_import - -import pytest +from __future__ import absolute_import, division, print_function import astroid +import pytest import pylint.extensions._check_docs_utils as utils diff --git a/pylint/test/extensions/test_check_raise_docs.py b/pylint/test/extensions/test_check_raise_docs.py index 64ffe5b265..c51a1fdaae 100644 --- a/pylint/test/extensions/test_check_raise_docs.py +++ b/pylint/test/extensions/test_check_raise_docs.py @@ -10,12 +10,12 @@ """Unit tests for the raised exception documentation checking in the `DocstringChecker` in :mod:`pylint.extensions.check_docs` """ -from __future__ import division, print_function, absolute_import +from __future__ import absolute_import, division, print_function import astroid -from pylint.testutils import CheckerTestCase, Message, set_config from pylint.extensions.docparams import DocstringParameterChecker +from pylint.testutils import CheckerTestCase, Message, set_config class TestDocstringCheckerRaise(CheckerTestCase): diff --git a/pylint/test/extensions/test_check_return_docs.py b/pylint/test/extensions/test_check_return_docs.py index db44886ef3..29de723101 100644 --- a/pylint/test/extensions/test_check_return_docs.py +++ b/pylint/test/extensions/test_check_return_docs.py @@ -12,12 +12,12 @@ """Unit tests for the return documentation checking in the `DocstringChecker` in :mod:`pylint.extensions.check_docs` """ -from __future__ import division, print_function, absolute_import +from __future__ import absolute_import, division, print_function import astroid -from pylint.testutils import CheckerTestCase, Message, set_config from pylint.extensions.docparams import DocstringParameterChecker +from pylint.testutils import CheckerTestCase, Message, set_config class TestDocstringCheckerReturn(CheckerTestCase): diff --git a/pylint/test/extensions/test_check_yields_docs.py b/pylint/test/extensions/test_check_yields_docs.py index 0d800b7e79..85c75c02d6 100644 --- a/pylint/test/extensions/test_check_yields_docs.py +++ b/pylint/test/extensions/test_check_yields_docs.py @@ -9,12 +9,12 @@ """Unit tests for the yield documentation checking in the `DocstringChecker` in :mod:`pylint.extensions.check_docs` """ -from __future__ import division, print_function, absolute_import +from __future__ import absolute_import, division, print_function import astroid -from pylint.testutils import CheckerTestCase, Message, set_config from pylint.extensions.docparams import DocstringParameterChecker +from pylint.testutils import CheckerTestCase, Message, set_config class TestDocstringCheckerYield(CheckerTestCase): diff --git a/pylint/test/extensions/test_docstyle.py b/pylint/test/extensions/test_docstyle.py index 7ced9a15e2..c4d3d881c2 100644 --- a/pylint/test/extensions/test_docstyle.py +++ b/pylint/test/extensions/test_docstyle.py @@ -14,7 +14,6 @@ from pylint.extensions.docstyle import DocStringStyleChecker - EXPECTED_MSGS = [ 'First line empty in function docstring', 'First line empty in class docstring', diff --git a/pylint/test/extensions/test_emptystring.py b/pylint/test/extensions/test_emptystring.py index c935b3bb87..c7ff30b50c 100644 --- a/pylint/test/extensions/test_emptystring.py +++ b/pylint/test/extensions/test_emptystring.py @@ -11,6 +11,7 @@ """ import os.path as osp + import pytest from pylint.extensions.emptystring import CompareToEmptyStringChecker diff --git a/pylint/test/extensions/test_overlapping_exceptions.py b/pylint/test/extensions/test_overlapping_exceptions.py index 44b98515a8..d001b20532 100644 --- a/pylint/test/extensions/test_overlapping_exceptions.py +++ b/pylint/test/extensions/test_overlapping_exceptions.py @@ -4,13 +4,13 @@ """Tests for the pylint checker in :mod:`pylint.extensions.overlapping_exceptions """ +from os.path import dirname, join from sys import version_info -from os.path import join, dirname - -from pylint.extensions.overlapping_exceptions import OverlappingExceptionsChecker import pytest +from pylint.extensions.overlapping_exceptions import OverlappingExceptionsChecker + @pytest.fixture(scope='module') def checker(checker): diff --git a/pylint/test/extensions/test_redefined.py b/pylint/test/extensions/test_redefined.py index f4e2c79d6f..85871b064f 100644 --- a/pylint/test/extensions/test_redefined.py +++ b/pylint/test/extensions/test_redefined.py @@ -14,7 +14,6 @@ from pylint.extensions.redefined_variable_type import MultipleTypesChecker from pylint.lint import fix_import_path - EXPECTED = [ 'Redefinition of self.var1 type from int to float', 'Redefinition of var type from int to str', diff --git a/pylint/test/test_func.py b/pylint/test/test_func.py index 0d9694545d..1566df9928 100644 --- a/pylint/test/test_func.py +++ b/pylint/test/test_func.py @@ -13,11 +13,11 @@ """functional/non regression tests for pylint""" -import sys import re +import sys +from os.path import abspath, dirname, join import pytest -from os.path import abspath, dirname, join from pylint.testutils import _get_tests_info, linter diff --git a/pylint/test/test_functional.py b/pylint/test/test_functional.py index 576cd0d560..ae673bd135 100644 --- a/pylint/test/test_functional.py +++ b/pylint/test/test_functional.py @@ -12,24 +12,21 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING """Functional full-module tests for PyLint.""" -import csv import collections +import csv import io import operator import os +import platform import re import sys -import platform +import pytest import six from six.moves import configparser -import pytest +from pylint import checkers, interfaces, lint, reporters -from pylint import checkers -from pylint import interfaces -from pylint import lint -from pylint import reporters class test_dialect(csv.excel): if sys.version_info[0] < 3: diff --git a/pylint/test/test_import_graph.py b/pylint/test/test_import_graph.py index 218164565d..d7b0096934 100644 --- a/pylint/test/test_import_graph.py +++ b/pylint/test/test_import_graph.py @@ -14,10 +14,9 @@ import pytest -from pylint.checkers import initialize, imports -from pylint.lint import PyLinter - import pylint.testutils as testutils +from pylint.checkers import imports, initialize +from pylint.lint import PyLinter @pytest.fixture diff --git a/pylint/test/test_regr.py b/pylint/test/test_regr.py index c3e0260153..65e66eb20e 100644 --- a/pylint/test/test_regr.py +++ b/pylint/test/test_regr.py @@ -14,17 +14,16 @@ to be incorporated in the automatic functional test framework """ -import sys import os +import sys from os.path import abspath, dirname, join +import astroid import pytest -import astroid import pylint.testutils as testutils from pylint import epylint - REGR_DATA = join(dirname(abspath(__file__)), "regrtest_data") sys.path.insert(1, REGR_DATA) diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py index 8fa262f17e..1ef4d2f9b9 100644 --- a/pylint/test/test_self.py +++ b/pylint/test/test_self.py @@ -20,25 +20,26 @@ # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html # For details: https://github.com/PyCQA/pylint/blob/master/COPYING +import configparser import contextlib import json +import os import re +import subprocess import sys -import os -from os.path import join, dirname, abspath import tempfile import textwrap -import configparser from io import StringIO -import subprocess +from os.path import abspath, dirname, join from unittest import mock +import pytest + +from pylint import utils from pylint.lint import Run from pylint.reporters import BaseReporter -from pylint.reporters.text import * from pylint.reporters.json import JSONReporter -import pytest -from pylint import utils +from pylint.reporters.text import * HERE = abspath(dirname(__file__)) diff --git a/pylint/test/unittest_checker_base.py b/pylint/test/unittest_checker_base.py index a1607cf8d1..1feae5b7ac 100644 --- a/pylint/test/unittest_checker_base.py +++ b/pylint/test/unittest_checker_base.py @@ -22,6 +22,7 @@ import unittest import astroid + from pylint.checkers import base from pylint.testutils import CheckerTestCase, Message, set_config diff --git a/pylint/test/unittest_checker_classes.py b/pylint/test/unittest_checker_classes.py index 1bf929b71c..3925cc36d7 100644 --- a/pylint/test/unittest_checker_classes.py +++ b/pylint/test/unittest_checker_classes.py @@ -10,6 +10,7 @@ """Unit tests for the variables checker.""" import astroid + from pylint.checkers import classes from pylint.testutils import CheckerTestCase, Message, set_config diff --git a/pylint/test/unittest_checker_format.py b/pylint/test/unittest_checker_format.py index 8811b08229..c47b4e54bf 100644 --- a/pylint/test/unittest_checker_format.py +++ b/pylint/test/unittest_checker_format.py @@ -24,18 +24,15 @@ from __future__ import unicode_literals -import tokenize import os import tempfile +import tokenize import astroid +from pylint import lint, reporters from pylint.checkers.format import * -from pylint import reporters -from pylint import lint - - -from pylint.testutils import CheckerTestCase, Message, set_config, _tokenize_str +from pylint.testutils import CheckerTestCase, Message, _tokenize_str, set_config class TestMultiStatementLine(CheckerTestCase): diff --git a/pylint/test/unittest_checker_imports.py b/pylint/test/unittest_checker_imports.py index b5961b26de..898be4ef59 100644 --- a/pylint/test/unittest_checker_imports.py +++ b/pylint/test/unittest_checker_imports.py @@ -14,9 +14,10 @@ import os import astroid + from pylint.checkers import imports -from pylint.testutils import CheckerTestCase, Message, set_config from pylint.interfaces import UNDEFINED +from pylint.testutils import CheckerTestCase, Message, set_config REGR_DATA = os.path.join(os.path.dirname(__file__), "regrtest_data", "") diff --git a/pylint/test/unittest_checker_misc.py b/pylint/test/unittest_checker_misc.py index 3fe49628d7..b72b7acaa2 100644 --- a/pylint/test/unittest_checker_misc.py +++ b/pylint/test/unittest_checker_misc.py @@ -13,7 +13,7 @@ """Tests for the misc checker.""" from pylint.checkers import misc -from pylint.testutils import CheckerTestCase, Message, set_config, _tokenize_str +from pylint.testutils import CheckerTestCase, Message, _tokenize_str, set_config class TestFixme(CheckerTestCase): diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index bc4c346b70..417bc2bb6b 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -20,14 +20,12 @@ import sys import textwrap -import pytest - import astroid +import pytest from pylint import testutils from pylint.checkers import python3 as checker -from pylint.interfaces import INFERENCE_FAILURE, INFERENCE - +from pylint.interfaces import INFERENCE, INFERENCE_FAILURE # Decorator for any tests that will fail under Python 3 python2_only = pytest.mark.skipif(sys.version_info[0] > 2, reason="Python 2 only") diff --git a/pylint/test/unittest_checker_similar.py b/pylint/test/unittest_checker_similar.py index f2cd901a83..a84883372d 100644 --- a/pylint/test/unittest_checker_similar.py +++ b/pylint/test/unittest_checker_similar.py @@ -10,10 +10,10 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING import sys -from os.path import join, dirname, abspath from contextlib import redirect_stdout - from io import StringIO +from os.path import abspath, dirname, join + import pytest from pylint.checkers import similar diff --git a/pylint/test/unittest_checker_spelling.py b/pylint/test/unittest_checker_spelling.py index f6b5ec2eda..8abd85577a 100644 --- a/pylint/test/unittest_checker_spelling.py +++ b/pylint/test/unittest_checker_spelling.py @@ -12,12 +12,11 @@ """Unittest for the spelling checker.""" -import pytest - import astroid +import pytest from pylint.checkers import spelling -from pylint.testutils import CheckerTestCase, Message, set_config, _tokenize_str +from pylint.testutils import CheckerTestCase, Message, _tokenize_str, set_config # try to create enchant dictionary try: diff --git a/pylint/test/unittest_checker_stdlib.py b/pylint/test/unittest_checker_stdlib.py index f425b0f99b..55c3dc8dc1 100644 --- a/pylint/test/unittest_checker_stdlib.py +++ b/pylint/test/unittest_checker_stdlib.py @@ -11,8 +11,8 @@ import astroid from pylint.checkers import stdlib -from pylint.testutils import CheckerTestCase, Message from pylint.interfaces import UNDEFINED +from pylint.testutils import CheckerTestCase, Message @contextlib.contextmanager diff --git a/pylint/test/unittest_checker_strings.py b/pylint/test/unittest_checker_strings.py index 4cac737479..bc4fce6f93 100644 --- a/pylint/test/unittest_checker_strings.py +++ b/pylint/test/unittest_checker_strings.py @@ -9,7 +9,6 @@ from pylint.checkers import strings from pylint.testutils import CheckerTestCase, Message - TEST_TOKENS = ( '"X"', "'X'", diff --git a/pylint/test/unittest_checker_typecheck.py b/pylint/test/unittest_checker_typecheck.py index 71fa7e82b5..a418087c2c 100644 --- a/pylint/test/unittest_checker_typecheck.py +++ b/pylint/test/unittest_checker_typecheck.py @@ -16,9 +16,8 @@ """Unittest for the type checker.""" import sys -import pytest - import astroid +import pytest from pylint.checkers import typecheck from pylint.testutils import CheckerTestCase, Message, set_config diff --git a/pylint/test/unittest_checker_variables.py b/pylint/test/unittest_checker_variables.py index a9b590a0a3..299a550d26 100644 --- a/pylint/test/unittest_checker_variables.py +++ b/pylint/test/unittest_checker_variables.py @@ -13,15 +13,15 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING """Unit tests for the variables checker.""" -import sys import os import re +import sys import astroid from pylint.checkers import variables -from pylint.testutils import CheckerTestCase, linter, set_config, Message from pylint.interfaces import UNDEFINED +from pylint.testutils import CheckerTestCase, Message, linter, set_config class TestVariablesChecker(CheckerTestCase): diff --git a/pylint/test/unittest_checkers_utils.py b/pylint/test/unittest_checkers_utils.py index 3471912c3b..7552d8c7ce 100644 --- a/pylint/test/unittest_checkers_utils.py +++ b/pylint/test/unittest_checkers_utils.py @@ -12,9 +12,9 @@ """Tests for the pylint.checkers.utils module.""" import astroid +import pytest from pylint.checkers import utils -import pytest @pytest.mark.parametrize( diff --git a/pylint/test/unittest_config.py b/pylint/test/unittest_config.py index 17e48d5a8a..ca36c00ebd 100644 --- a/pylint/test/unittest_config.py +++ b/pylint/test/unittest_config.py @@ -12,9 +12,9 @@ import re import sre_constants -from pylint import config import pytest +from pylint import config RE_PATTERN_TYPE = getattr(re, "Pattern", getattr(re, "_pattern_type", None)) diff --git a/pylint/test/unittest_pyreverse_diadefs.py b/pylint/test/unittest_pyreverse_diadefs.py index 6414979053..0659a5b11a 100644 --- a/pylint/test/unittest_pyreverse_diadefs.py +++ b/pylint/test/unittest_pyreverse_diadefs.py @@ -13,13 +13,11 @@ unit test for the extensions.diadefslib modules """ -import pytest - import astroid +import pytest -from pylint.pyreverse.inspector import Linker from pylint.pyreverse.diadefslib import * - +from pylint.pyreverse.inspector import Linker from unittest_pyreverse_writer import Config, get_project diff --git a/pylint/test/unittest_pyreverse_inspector.py b/pylint/test/unittest_pyreverse_inspector.py index f87bddbfde..c4433ba517 100644 --- a/pylint/test/unittest_pyreverse_inspector.py +++ b/pylint/test/unittest_pyreverse_inspector.py @@ -9,11 +9,9 @@ """ import os -import pytest - import astroid -from astroid import nodes -from astroid import bases +import pytest +from astroid import bases, nodes from pylint.pyreverse import inspector from unittest_pyreverse_writer import get_project diff --git a/pylint/test/unittest_pyreverse_writer.py b/pylint/test/unittest_pyreverse_writer.py index cf2e915b0f..01654024ae 100644 --- a/pylint/test/unittest_pyreverse_writer.py +++ b/pylint/test/unittest_pyreverse_writer.py @@ -15,17 +15,16 @@ """ -import os import codecs +import os from difflib import unified_diff import pytest -from pylint.pyreverse.inspector import Linker, project_from_files from pylint.pyreverse.diadefslib import DefaultDiadefGenerator, DiadefsHandler -from pylint.pyreverse.writer import DotWriter +from pylint.pyreverse.inspector import Linker, project_from_files from pylint.pyreverse.utils import get_visibility - +from pylint.pyreverse.writer import DotWriter _DEFAULTS = { "all_ancestors": None, diff --git a/pylint/test/unittest_reporters_json.py b/pylint/test/unittest_reporters_json.py index ba78538874..f3424ab669 100644 --- a/pylint/test/unittest_reporters_json.py +++ b/pylint/test/unittest_reporters_json.py @@ -11,11 +11,10 @@ """Test for the JSON reporter.""" import json - from io import StringIO -from pylint.lint import PyLinter from pylint import checkers +from pylint.lint import PyLinter from pylint.reporters.json import JSONReporter diff --git a/pylint/test/unittest_reporting.py b/pylint/test/unittest_reporting.py index 88f2ce4d52..a374e1e3ea 100644 --- a/pylint/test/unittest_reporting.py +++ b/pylint/test/unittest_reporting.py @@ -11,14 +11,14 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING import warnings - from io import StringIO -from pylint.lint import PyLinter -from pylint import checkers -from pylint.reporters.text import TextReporter, ParseableTextReporter import pytest +from pylint import checkers +from pylint.lint import PyLinter +from pylint.reporters.text import ParseableTextReporter, TextReporter + @pytest.fixture(scope="module") def reporter(reporter): diff --git a/pylint/test/utils/unittest_utils.py b/pylint/test/utils/unittest_utils.py index 6ad932dc61..8ed2f26c92 100644 --- a/pylint/test/utils/unittest_utils.py +++ b/pylint/test/utils/unittest_utils.py @@ -22,8 +22,8 @@ import astroid -from pylint.utils import utils, ASTWalker from pylint.checkers.utils import check_messages, get_node_last_lineno +from pylint.utils import ASTWalker, utils class TestASTWalker(object): diff --git a/pylint/testutils.py b/pylint/testutils.py index 17ded416a8..d47f67dd04 100644 --- a/pylint/testutils.py +++ b/pylint/testutils.py @@ -25,22 +25,22 @@ import collections import contextlib import functools -from glob import glob import os -from os import linesep, getcwd, sep -from os.path import abspath, basename, dirname, join, splitext import sys import tempfile import tokenize - +from glob import glob from io import StringIO +from os import getcwd, linesep, sep +from os.path import abspath, basename, dirname, join, splitext import astroid + from pylint import checkers -from pylint.utils import ASTWalker -from pylint.reporters import BaseReporter from pylint.interfaces import IReporter from pylint.lint import PyLinter +from pylint.reporters import BaseReporter +from pylint.utils import ASTWalker # Utils diff --git a/pylint/utils/__init__.py b/pylint/utils/__init__.py index 1b29540782..51b12f75dd 100644 --- a/pylint/utils/__init__.py +++ b/pylint/utils/__init__.py @@ -41,10 +41,10 @@ main pylint class """ +from pylint.utils.ast_walker import ASTWalker from pylint.utils.constants import OPTION_RGX, PY_EXTS from pylint.utils.file_state import FileState from pylint.utils.normalize_text import normalize_text -from pylint.utils.ast_walker import ASTWalker from pylint.utils.reports_handler_mix_in import ReportsHandlerMixIn from pylint.utils.utils import ( _basename_in_blacklist_re, diff --git a/pylint/utils/file_state.py b/pylint/utils/file_state.py index 46180833a9..2bc1662aa7 100644 --- a/pylint/utils/file_state.py +++ b/pylint/utils/file_state.py @@ -6,6 +6,7 @@ import collections from astroid import nodes + from pylint.message.constants import MSG_STATE_SCOPE_MODULE from pylint.utils.warning_scope import WarningScope diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index fb8e1ef10a..3147ac847d 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -13,8 +13,9 @@ from os.path import basename, dirname, exists, isdir, join, normpath, splitext from astroid import Module, modutils -from pylint.utils.constants import PY_EXTS + from pylint.message.constants import MSG_TYPES, MSG_TYPES_LONG +from pylint.utils.constants import PY_EXTS from pylint.utils.normalize_text import normalize_text diff --git a/setup.py b/setup.py index a7b5e4138c..77e0e2fff7 100644 --- a/setup.py +++ b/setup.py @@ -21,12 +21,15 @@ """Generic Setup script, takes package info from __pkginfo__.py file. """ from __future__ import absolute_import, print_function -__docformat__ = "restructuredtext en" import os -import sys import shutil -from os.path import isdir, exists, join +import sys +from distutils.command.build_py import build_py +from os.path import exists, isdir, join + +__docformat__ = "restructuredtext en" + try: from setuptools import setup @@ -39,7 +42,6 @@ USE_SETUPTOOLS = 0 easy_install_lib = None -from distutils.command.build_py import build_py base_dir = os.path.dirname(__file__) From 318ccd6b56cdb844f4c1cbe7fb34cfb0c9e79f94 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 9 Mar 2019 11:23:15 +0100 Subject: [PATCH 4/9] Style - Re-Apply black following the isort cleanup Change with isort triggered change with black. --- doc/conf.py | 127 ++++++++++---------- doc/exts/pylint_extensions.py | 75 ++++++------ doc/exts/pylint_features.py | 12 +- examples/custom.py | 32 ++--- examples/custom_raw.py | 22 ++-- pylint/__main__.py | 1 - pylint/checkers/similar.py | 4 +- pylint/checkers/spelling.py | 1 - pylint/config.py | 3 - pylint/extensions/mccabe.py | 1 - pylint/lint.py | 1 - pylint/pyreverse/__init__.py | 1 - pylint/test/extensions/test_check_docs.py | 6 +- pylint/test/test_functional.py | 4 +- pylint/test/unittest_checker_typecheck.py | 2 +- pylint/test/unittest_pyreverse_inspector.py | 2 +- setup.py | 123 ++++++++++--------- 17 files changed, 216 insertions(+), 201 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 16bfb7eb9f..f71c4d3415 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -25,204 +25,204 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.append(os.path.abspath('exts')) +sys.path.append(os.path.abspath("exts")) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ - 'pylint_features', - 'pylint_extensions', - 'sphinx.ext.autosectionlabel', - 'sphinx.ext.intersphinx', + "pylint_features", + "pylint_extensions", + "sphinx.ext.autosectionlabel", + "sphinx.ext.intersphinx", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'Pylint' +project = "Pylint" current_year = datetime.utcnow().year -copyright = '2003-{year}, Logilab, PyCQA and contributors'.format(year=current_year) +copyright = "2003-{year}, Logilab, PyCQA and contributors".format(year=current_year) # The full version, including alpha/beta/rc tags. release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'python_docs_theme' +html_theme = "python_docs_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. html_theme_options = { - 'collapsiblesidebar': True, - 'issues_url': 'https://github.com/pycqa/pylint/issues/new', - 'root_name': 'PyCQA', - 'root_url': 'http://meta.pycqa.org/en/latest/', + "collapsiblesidebar": True, + "issues_url": "https://github.com/pycqa/pylint/issues/new", + "root_name": "PyCQA", + "root_url": "http://meta.pycqa.org/en/latest/", } # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +# html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' smartquotes = False # Custom sidebar templates, maps document names to template names. html_sidebars = { - '**': [ - 'localtoc.html', - 'globaltoc.html', - 'relations.html', - 'sourcelink.html' - ] + "**": ["localtoc.html", "globaltoc.html", "relations.html", "sourcelink.html"] } # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'Pylintdoc' +htmlhelp_basename = "Pylintdoc" # -- Options for LaTeX output -------------------------------------------------- # The paper size ('letter' or 'a4'). -#latex_paper_size = 'letter' +# latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). -#latex_font_size = '10pt' +# latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'Pylint.tex', 'Pylint Documentation', - 'Logilab, PyCQA and contributors', 'manual'), + ( + "index", + "Pylint.tex", + "Pylint Documentation", + "Logilab, PyCQA and contributors", + "manual", + ) ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Additional stuff for the LaTeX preamble. -#latex_preamble = '' +# latex_preamble = '' # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output -------------------------------------------- @@ -230,13 +230,12 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'pylint', 'Pylint Documentation', - ['Logilab, PyCQA and contributors'], 1) + ("index", "pylint", "Pylint Documentation", ["Logilab, PyCQA and contributors"], 1) ] intersphinx_mapping = { - 'astroid': ('http://astroid.readthedocs.io/en/latest/', None), - 'python': ('https://docs.python.org/3', None), + "astroid": ("http://astroid.readthedocs.io/en/latest/", None), + "python": ("https://docs.python.org/3", None), } # Prevent label issues due to colliding section names diff --git a/doc/exts/pylint_extensions.py b/doc/exts/pylint_extensions.py index 2e1d821635..dd660767c9 100755 --- a/doc/exts/pylint_extensions.py +++ b/doc/exts/pylint_extensions.py @@ -18,28 +18,27 @@ # 1) They are deprecated, why document them moving forward? # 2) We can't load the deprecated module and the newly renamed module at the # same time without getting naming conflicts -DEPRECATED_MODULES = [ - 'check_docs', # ==> docparams -] +DEPRECATED_MODULES = ["check_docs"] # ==> docparams + def builder_inited(app): """Output full documentation in ReST format for all extension modules""" # PACKAGE/docs/exts/pylint_extensions.py --> PACKAGE/ base_path = os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + ) # PACKAGE/ --> PACKAGE/pylint/extensions - ext_path = os.path.join(base_path, 'pylint', 'extensions') + ext_path = os.path.join(base_path, "pylint", "extensions") modules = [] doc_files = {} for filename in os.listdir(ext_path): name, ext = os.path.splitext(filename) - if name[0] == '_' or name in DEPRECATED_MODULES: + if name[0] == "_" or name in DEPRECATED_MODULES: continue - if ext == '.py': - modules.append('pylint.extensions.%s' % name) - elif ext == '.rst': - doc_files['pylint.extensions.' + name] = os.path.join(ext_path, - filename) + if ext == ".py": + modules.append("pylint.extensions.%s" % name) + elif ext == ".rst": + doc_files["pylint.extensions." + name] = os.path.join(ext_path, filename) modules.sort() if not modules: sys.exit("No Pylint extensions found?") @@ -47,29 +46,35 @@ def builder_inited(app): linter = PyLinter() linter.load_plugin_modules(modules) - extensions_doc = os.path.join(base_path, 'doc', 'technical_reference', 'extensions.rst') - with open(extensions_doc, 'w') as stream: + extensions_doc = os.path.join( + base_path, "doc", "technical_reference", "extensions.rst" + ) + with open(extensions_doc, "w") as stream: stream.write("Optional Pylint checkers in the extensions module\n") stream.write("=================================================\n\n") stream.write("Pylint provides the following optional plugins:\n\n") for module in modules: stream.write("- :ref:`{}`\n".format(module)) stream.write("\n") - stream.write("You can activate any or all of these extensions " - "by adding a ``load-plugins`` line to the ``MASTER`` " - "section of your ``.pylintrc``, for example::\n") - stream.write("\n load-plugins=pylint.extensions.docparams," - "pylint.extensions.docstyle\n\n") + stream.write( + "You can activate any or all of these extensions " + "by adding a ``load-plugins`` line to the ``MASTER`` " + "section of your ``.pylintrc``, for example::\n" + ) + stream.write( + "\n load-plugins=pylint.extensions.docparams," + "pylint.extensions.docstyle\n\n" + ) by_module = get_plugins_info(linter, doc_files) for module, info in sorted(by_module.items()): - linter._print_checker_doc(info['name'], info, stream=stream) + linter._print_checker_doc(info["name"], info, stream=stream) def get_plugins_info(linter, doc_files): by_module = {} for checker in linter.get_checkers(): - if checker.name == 'master': + if checker.name == "master": continue module = checker.__module__ # Plugins only - skip over core checkers @@ -80,32 +85,32 @@ def get_plugins_info(linter, doc_files): doc = "" doc_file = doc_files.get(module) if doc_file: - with open(doc_file, 'r') as f: + with open(doc_file, "r") as f: doc = f.read() try: - by_module[module]['options'] += checker.options_and_values() - by_module[module]['msgs'].update(checker.msgs) - by_module[module]['reports'] += checker.reports - by_module[module]['doc'] += doc - by_module[module]['name'] += checker.name - by_module[module]['module'] += module + by_module[module]["options"] += checker.options_and_values() + by_module[module]["msgs"].update(checker.msgs) + by_module[module]["reports"] += checker.reports + by_module[module]["doc"] += doc + by_module[module]["name"] += checker.name + by_module[module]["module"] += module except KeyError: by_module[module] = { - 'options': list(checker.options_and_values()), - 'msgs': dict(checker.msgs), - 'reports': list(checker.reports), - 'doc': doc, - 'name': checker.name, - 'module': module, + "options": list(checker.options_and_values()), + "msgs": dict(checker.msgs), + "reports": list(checker.reports), + "doc": doc, + "name": checker.name, + "module": module, } return by_module def setup(app): - app.connect('builder-inited', builder_inited) - return {'version': sphinx.__display_version__} + app.connect("builder-inited", builder_inited) + return {"version": sphinx.__display_version__} if __name__ == "__main__": diff --git a/doc/exts/pylint_features.py b/doc/exts/pylint_features.py index 2ff0e52a76..4803efc9ac 100755 --- a/doc/exts/pylint_features.py +++ b/doc/exts/pylint_features.py @@ -15,12 +15,13 @@ def builder_inited(app): # PACKAGE/docs/exts/pylint_extensions.py --> PACKAGE/ base_path = os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + ) linter = PyLinter() linter.load_default_plugins() - features = os.path.join(base_path, 'doc', 'technical_reference', 'features.rst') - with open(features, 'w') as stream: + features = os.path.join(base_path, "doc", "technical_reference", "features.rst") + with open(features, "w") as stream: stream.write("Pylint features\n") stream.write("===============\n\n") stream.write(".. generated by pylint --full-documentation\n\n") @@ -28,8 +29,9 @@ def builder_inited(app): def setup(app): - app.connect('builder-inited', builder_inited) - return {'version': sphinx.__display_version__} + app.connect("builder-inited", builder_inited) + return {"version": sphinx.__display_version__} + if __name__ == "__main__": builder_inited(None) diff --git a/examples/custom.py b/examples/custom.py index 039b018b8b..7ee97bb5fd 100644 --- a/examples/custom.py +++ b/examples/custom.py @@ -14,7 +14,7 @@ class MyAstroidChecker(BaseChecker): __implements__ = IAstroidChecker # The name defines a custom section of the config for this checker. - name = 'custom' + name = "custom" # The priority indicates the order that pylint will run the checkers. priority = -1 # This class variable declares the messages (ie the warnings and errors) @@ -24,9 +24,7 @@ class MyAstroidChecker(BaseChecker): # a unique symbol that identifies the message, # and a detailed help message # that will be included in the documentation. - 'W0001': ('Message that will be emitted', - 'message-symbol', - 'Message help') + "W0001": ("Message that will be emitted", "message-symbol", "Message help") } # This class variable declares the options # that are configurable by the user. @@ -35,12 +33,16 @@ class MyAstroidChecker(BaseChecker): # and in config files, and a dictionary of arguments # (similar to those to those to # argparse.ArgumentParser.add_argument). - ('store-locals-indicator', - {'default': 'properties', - 'help': ('The expression name that indicates that the locals should ' - 'be stored'), - }, - ), + ( + "store-locals-indicator", + { + "default": "properties", + "help": ( + "The expression name that indicates that the locals should " + "be stored" + ), + }, + ), ) def visit_call(self, node): @@ -51,10 +53,12 @@ def visit_call(self, node): :param node: The node to check. :type node: astroid.node_classes.Call """ - if not (isinstance(node.func, astroid.Attribute) - and isinstance(node.func.expr, astroid.Name) - and node.func.expr.name == self.config.store_locals_indicator - and node.func.attrname == 'create'): + if not ( + isinstance(node.func, astroid.Attribute) + and isinstance(node.func.expr, astroid.Name) + and node.func.expr.name == self.config.store_locals_indicator + and node.func.attrname == "create" + ): return in_class = node.frame() for param in node.args: diff --git a/examples/custom_raw.py b/examples/custom_raw.py index fb28d49311..63e4aeb8ee 100644 --- a/examples/custom_raw.py +++ b/examples/custom_raw.py @@ -9,12 +9,17 @@ class MyRawChecker(BaseChecker): __implements__ = IRawChecker - name = 'custom_raw' - msgs = {'W9901': ('use \\ for line continuation', - 'backslash-line-continuation', - ('Used when a \\ is used for a line continuation instead' - ' of using triple quoted string or parenthesis.')), - } + name = "custom_raw" + msgs = { + "W9901": ( + "use \\ for line continuation", + "backslash-line-continuation", + ( + "Used when a \\ is used for a line continuation instead" + " of using triple quoted string or parenthesis." + ), + ) + } options = () def process_module(self, node): @@ -24,9 +29,8 @@ def process_module(self, node): """ with node.stream() as stream: for (lineno, line) in enumerate(stream): - if line.rstrip().endswith('\\'): - self.add_message('backslash-line-continuation', - line=lineno) + if line.rstrip().endswith("\\"): + self.add_message("backslash-line-continuation", line=lineno) def register(linter): diff --git a/pylint/__main__.py b/pylint/__main__.py index 7eca119293..e12309b4da 100644 --- a/pylint/__main__.py +++ b/pylint/__main__.py @@ -1,4 +1,3 @@ - # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html # For details: https://github.com/PyCQA/pylint/blob/master/COPYING diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index d79785d667..f65f533cd9 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -109,7 +109,7 @@ def _display_sims(self, sims): % ( nb_total_lignes, nb_lignes_dupliquees, - nb_lignes_dupliquees * 100. / nb_total_lignes, + nb_lignes_dupliquees * 100.0 / nb_total_lignes, ) ) @@ -387,7 +387,7 @@ def close(self): self.add_message("R0801", args=(len(couples), "\n".join(msg))) duplicated += num * (len(couples) - 1) stats["nb_duplicated_lines"] = duplicated - stats["percent_duplicated_lines"] = total and duplicated * 100. / total + stats["percent_duplicated_lines"] = total and duplicated * 100.0 / total def register(linter): diff --git a/pylint/checkers/spelling.py b/pylint/checkers/spelling.py index f1952e89fc..c1a0eb2de3 100644 --- a/pylint/checkers/spelling.py +++ b/pylint/checkers/spelling.py @@ -47,7 +47,6 @@ class Chunker: # type: ignore pass - if enchant is not None: br = enchant.Broker() dicts = br.list_dicts() diff --git a/pylint/config.py b/pylint/config.py index a913f86199..8b0373f612 100644 --- a/pylint/config.py +++ b/pylint/config.py @@ -57,9 +57,6 @@ # need a cleanup. It could be completely reengineered as well. - - - USER_HOME = os.path.expanduser("~") if "PYLINTHOME" in os.environ: PYLINT_HOME = os.environ["PYLINTHOME"] diff --git a/pylint/extensions/mccabe.py b/pylint/extensions/mccabe.py index 69bc1775ba..18baa2601b 100644 --- a/pylint/extensions/mccabe.py +++ b/pylint/extensions/mccabe.py @@ -11,7 +11,6 @@ from mccabe import PathGraph as Mccabe_PathGraph from mccabe import PathGraphingAstVisitor as Mccabe_PathGraphingAstVisitor - from pylint import checkers from pylint.checkers.utils import check_messages from pylint.interfaces import HIGH, IAstroidChecker diff --git a/pylint/lint.py b/pylint/lint.py index d02410fa08..25129ecb1d 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -86,7 +86,6 @@ multiprocessing = None # type: ignore - MANAGER = astroid.MANAGER diff --git a/pylint/pyreverse/__init__.py b/pylint/pyreverse/__init__.py index 8a12c4fec5..9ca1da5c6a 100644 --- a/pylint/pyreverse/__init__.py +++ b/pylint/pyreverse/__init__.py @@ -1,4 +1,3 @@ - # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html # For details: https://github.com/PyCQA/pylint/blob/master/COPYING diff --git a/pylint/test/extensions/test_check_docs.py b/pylint/test/extensions/test_check_docs.py index 63825c415f..1eacc93878 100644 --- a/pylint/test/extensions/test_check_docs.py +++ b/pylint/test/extensions/test_check_docs.py @@ -762,7 +762,7 @@ class ClassFoo(object): '''docstring foo :param y: bla - + missing constructor parameter documentation ''' @@ -794,7 +794,7 @@ class ClassFoo(object): Args: y: bla - + missing constructor parameter documentation ''' @@ -828,7 +828,7 @@ class ClassFoo(object): ---------- y: bla - + missing constructor parameter documentation ''' diff --git a/pylint/test/test_functional.py b/pylint/test/test_functional.py index ae673bd135..1280631652 100644 --- a/pylint/test/test_functional.py +++ b/pylint/test/test_functional.py @@ -22,10 +22,10 @@ import sys import pytest -import six -from six.moves import configparser +import six from pylint import checkers, interfaces, lint, reporters +from six.moves import configparser class test_dialect(csv.excel): diff --git a/pylint/test/unittest_checker_typecheck.py b/pylint/test/unittest_checker_typecheck.py index a418087c2c..7bce396c5c 100644 --- a/pylint/test/unittest_checker_typecheck.py +++ b/pylint/test/unittest_checker_typecheck.py @@ -50,7 +50,7 @@ def test_no_member_in_getattr(self): node = astroid.extract_node( """ import optparse - optparse.THIS_does_not_EXIST + optparse.THIS_does_not_EXIST """ ) with self.assertAddsMessages( diff --git a/pylint/test/unittest_pyreverse_inspector.py b/pylint/test/unittest_pyreverse_inspector.py index c4433ba517..fe5df9b981 100644 --- a/pylint/test/unittest_pyreverse_inspector.py +++ b/pylint/test/unittest_pyreverse_inspector.py @@ -94,7 +94,7 @@ class MyIFace(Interface): pass class AnotherIFace(Interface): pass class Concrete0(object): __implements__ = MyIFace - class Concrete1: + class Concrete1: __implements__ = (MyIFace, AnotherIFace) class Concrete2: __implements__ = (MyIFace, AnotherIFace) diff --git a/setup.py b/setup.py index 77e0e2fff7..2e76e4878b 100644 --- a/setup.py +++ b/setup.py @@ -35,36 +35,37 @@ from setuptools import setup from setuptools.command import easy_install as easy_install_lib from setuptools.command import install_lib + USE_SETUPTOOLS = 1 except ImportError: from distutils.core import setup from distutils.command import install_lib + USE_SETUPTOOLS = 0 easy_install_lib = None - base_dir = os.path.dirname(__file__) __pkginfo__ = {} with open(os.path.join(base_dir, "pylint", "__pkginfo__.py")) as f: exec(f.read(), __pkginfo__) -modname = __pkginfo__['modname'] -distname = __pkginfo__.get('distname', modname) -scripts = __pkginfo__.get('scripts', []) -data_files = __pkginfo__.get('data_files', None) -include_dirs = __pkginfo__.get('include_dirs', []) -ext_modules = __pkginfo__.get('ext_modules', None) -install_requires = __pkginfo__.get('install_requires', None) -dependency_links = __pkginfo__.get('dependency_links', []) -extras_require = __pkginfo__.get('extras_require', {}) - -readme_path = join(base_dir, 'README.rst') +modname = __pkginfo__["modname"] +distname = __pkginfo__.get("distname", modname) +scripts = __pkginfo__.get("scripts", []) +data_files = __pkginfo__.get("data_files", None) +include_dirs = __pkginfo__.get("include_dirs", []) +ext_modules = __pkginfo__.get("ext_modules", None) +install_requires = __pkginfo__.get("install_requires", None) +dependency_links = __pkginfo__.get("dependency_links", []) +extras_require = __pkginfo__.get("extras_require", {}) + +readme_path = join(base_dir, "README.rst") if exists(readme_path): with open(readme_path) as stream: long_description = stream.read() else: - long_description = '' + long_description = "" def ensure_scripts(linux_scripts): @@ -72,8 +73,9 @@ def ensure_scripts(linux_scripts): (taken from 4Suite) """ from distutils import util - if util.get_platform()[:3] == 'win': - return linux_scripts + [script + '.bat' for script in linux_scripts] + + if util.get_platform()[:3] == "win": + return linux_scripts + [script + ".bat" for script in linux_scripts] return linux_scripts @@ -83,9 +85,9 @@ def get_packages(directory, prefix): for package in os.listdir(directory): absfile = join(directory, package) if isdir(absfile): - if exists(join(absfile, '__init__.py')): + if exists(join(absfile, "__init__.py")): if prefix: - result.append('%s.%s' % (prefix, package)) + result.append("%s.%s" % (prefix, package)) else: result.append(package) result += get_packages(absfile, result[-1]) @@ -93,7 +95,7 @@ def get_packages(directory, prefix): def _filter_tests(files): - testdir = join('pylint', 'test') + testdir = join("pylint", "test") return [f for f in files if testdir not in f] @@ -101,6 +103,7 @@ class MyInstallLib(install_lib.install_lib): """extend install_lib command to handle package __init__.py and include_dirs variable if necessary """ + def run(self): """overridden from install_lib class""" install_lib.install_lib.run(self) @@ -109,12 +112,13 @@ def run(self): for directory in include_dirs: dest = join(self.install_dir, directory) if sys.version_info >= (3, 0): - exclude = {'invalid_encoded_data*', 'unknown_encoding*'} + exclude = {"invalid_encoded_data*", "unknown_encoding*"} else: exclude = set() shutil.rmtree(dest, ignore_errors=True) - shutil.copytree(directory, dest, - ignore=shutil.ignore_patterns(*exclude)) + shutil.copytree( + directory, dest, ignore=shutil.ignore_patterns(*exclude) + ) # override this since pip/easy_install attempt to byte compile test data # files, some of them being syntactically wrong by design, and this scares @@ -125,6 +129,7 @@ def byte_compile(self, files): if easy_install_lib: + class easy_install(easy_install_lib.easy_install): # override this since pip/easy_install attempt to byte compile # test data files, some of them being syntactically wrong by design, @@ -137,43 +142,47 @@ def byte_compile(self, files): def install(**kwargs): """setup entry point""" if USE_SETUPTOOLS: - if '--force-manifest' in sys.argv: - sys.argv.remove('--force-manifest') - packages = [modname] + get_packages(join(base_dir, 'pylint'), modname) + if "--force-manifest" in sys.argv: + sys.argv.remove("--force-manifest") + packages = [modname] + get_packages(join(base_dir, "pylint"), modname) if USE_SETUPTOOLS: if install_requires: - kwargs['install_requires'] = install_requires - kwargs['dependency_links'] = dependency_links - kwargs['entry_points'] = {'console_scripts': [ - 'pylint = pylint:run_pylint', - 'epylint = pylint:run_epylint', - 'pyreverse = pylint:run_pyreverse', - 'symilar = pylint:run_symilar', - ]} - kwargs['packages'] = packages - cmdclass = {'install_lib': MyInstallLib, - 'build_py': build_py} + kwargs["install_requires"] = install_requires + kwargs["dependency_links"] = dependency_links + kwargs["entry_points"] = { + "console_scripts": [ + "pylint = pylint:run_pylint", + "epylint = pylint:run_epylint", + "pyreverse = pylint:run_pyreverse", + "symilar = pylint:run_symilar", + ] + } + kwargs["packages"] = packages + cmdclass = {"install_lib": MyInstallLib, "build_py": build_py} if easy_install_lib: - cmdclass['easy_install'] = easy_install - return setup(name=distname, - version=__pkginfo__['version'], - license=__pkginfo__['license'], - description=__pkginfo__['description'], - long_description=long_description, - author=__pkginfo__['author'], - author_email=__pkginfo__['author_email'], - url=__pkginfo__['web'], - scripts=ensure_scripts(scripts), - classifiers=__pkginfo__['classifiers'], - data_files=data_files, - ext_modules=ext_modules, - cmdclass=cmdclass, - extras_require=extras_require, - test_suite='test', - python_requires='>=3.4.*', - setup_requires=['pytest-runner'], - tests_require=['pytest'], - **kwargs) - -if __name__ == '__main__': + cmdclass["easy_install"] = easy_install + return setup( + name=distname, + version=__pkginfo__["version"], + license=__pkginfo__["license"], + description=__pkginfo__["description"], + long_description=long_description, + author=__pkginfo__["author"], + author_email=__pkginfo__["author_email"], + url=__pkginfo__["web"], + scripts=ensure_scripts(scripts), + classifiers=__pkginfo__["classifiers"], + data_files=data_files, + ext_modules=ext_modules, + cmdclass=cmdclass, + extras_require=extras_require, + test_suite="test", + python_requires=">=3.4.*", + setup_requires=["pytest-runner"], + tests_require=["pytest"], + **kwargs + ) + + +if __name__ == "__main__": install() From 2d954bd2434765649e61e1b90f78bc7614a6141f Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 9 Mar 2019 11:14:14 +0100 Subject: [PATCH 5/9] Fix - C0412: Imports from package x are not grouped --- pylint/checkers/imports.py | 14 +++++++------- pylint/extensions/mccabe.py | 1 + pylint/test/test_functional.py | 5 +++-- pylint/testutils.py | 11 +++++------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index 82ef94a079..6fc5400bcc 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -37,8 +37,6 @@ import astroid import isort -from astroid import are_exclusive, decorators -from astroid.modutils import get_module_part, is_standard_module from pylint.checkers import BaseChecker from pylint.checkers.utils import ( @@ -114,7 +112,7 @@ def _get_first_import(node, context, name, base, level, alias): break if found: break - if found and not are_exclusive(first, node): + if found and not astroid.are_exclusive(first, node): return first return None @@ -789,14 +787,16 @@ def _add_imported_module(self, node, importedmodname): base = os.path.splitext(os.path.basename(module_file))[0] try: - importedmodname = get_module_part(importedmodname, module_file) + importedmodname = astroid.modutils.get_module_part( + importedmodname, module_file + ) except ImportError: pass if context_name == importedmodname: self.add_message("import-self", node=node) - elif not is_standard_module(importedmodname): + elif not astroid.modutils.is_standard_module(importedmodname): # if this is not a package __init__ module if base != "__init__" and context_name not in self._module_pkg: # record the module's parent, or the module itself if this is @@ -897,14 +897,14 @@ def _filter_dependencies_graph(self, internal): graph[importee].add(importer) return graph - @decorators.cached + @astroid.decorators.cached def _external_dependencies_info(self): """return cached external dependencies information or build and cache them """ return self._filter_dependencies_graph(internal=False) - @decorators.cached + @astroid.decorators.cached def _internal_dependencies_info(self): """return cached internal dependencies information or build and cache them diff --git a/pylint/extensions/mccabe.py b/pylint/extensions/mccabe.py index 18baa2601b..69bc1775ba 100644 --- a/pylint/extensions/mccabe.py +++ b/pylint/extensions/mccabe.py @@ -11,6 +11,7 @@ from mccabe import PathGraph as Mccabe_PathGraph from mccabe import PathGraphingAstVisitor as Mccabe_PathGraphingAstVisitor + from pylint import checkers from pylint.checkers.utils import check_messages from pylint.interfaces import HIGH, IAstroidChecker diff --git a/pylint/test/test_functional.py b/pylint/test/test_functional.py index 1280631652..bb4145c4d4 100644 --- a/pylint/test/test_functional.py +++ b/pylint/test/test_functional.py @@ -12,6 +12,7 @@ # For details: https://github.com/PyCQA/pylint/blob/master/COPYING """Functional full-module tests for PyLint.""" + import collections import csv import io @@ -22,11 +23,11 @@ import sys import pytest - import six -from pylint import checkers, interfaces, lint, reporters from six.moves import configparser +from pylint import checkers, interfaces, lint, reporters + class test_dialect(csv.excel): if sys.version_info[0] < 3: diff --git a/pylint/testutils.py b/pylint/testutils.py index d47f67dd04..53e395881f 100644 --- a/pylint/testutils.py +++ b/pylint/testutils.py @@ -25,13 +25,12 @@ import collections import contextlib import functools -import os import sys import tempfile import tokenize from glob import glob from io import StringIO -from os import getcwd, linesep, sep +from os import close, getcwd, linesep, remove, sep, write from os.path import abspath, basename, dirname, join, splitext import astroid @@ -286,14 +285,14 @@ def _create_tempfile(content=None): if content: if sys.version_info >= (3, 0): # erff - os.write(file_handle, bytes(content, "ascii")) + write(file_handle, bytes(content, "ascii")) else: - os.write(file_handle, content) + write(file_handle, content) try: yield tmp finally: - os.close(file_handle) - os.remove(tmp) + close(file_handle) + remove(tmp) @contextlib.contextmanager From 0b250aef914f22e9b4b11a57788aa3cefb52bf60 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 9 Mar 2019 11:34:10 +0100 Subject: [PATCH 6/9] Fix - An error added when applying isort/black everywhere --- pylint/test/extensions/data/docstring.py | 3 +-- pylint/test/extensions/test_docstyle.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pylint/test/extensions/data/docstring.py b/pylint/test/extensions/data/docstring.py index 5a2c3fe63b..8f34c657f8 100644 --- a/pylint/test/extensions/data/docstring.py +++ b/pylint/test/extensions/data/docstring.py @@ -2,7 +2,7 @@ def check_messages(*messages): - """ + """ docstring""" return messages @@ -38,4 +38,3 @@ def method6(self): def method7(self): u"""Test OK 3 with unicode string""" - diff --git a/pylint/test/extensions/test_docstyle.py b/pylint/test/extensions/test_docstyle.py index c4d3d881c2..cad929d318 100644 --- a/pylint/test/extensions/test_docstyle.py +++ b/pylint/test/extensions/test_docstyle.py @@ -8,7 +8,7 @@ """Tests for the pylint checker in :mod:`pylint.extensions.check_docstring """ -import os.path as osp +from os.path import abspath, dirname, join import pytest @@ -41,8 +41,7 @@ def checker(checker): def test_docstring_message(linter): - docstring_test = osp.join(osp.dirname(osp.abspath(__file__)), 'data', - 'docstring.py') + docstring_test = join(dirname(abspath(__file__)), 'data', 'docstring.py') linter.check([docstring_test]) msgs = linter.reporter.messages assert len(msgs) == 7 From 44e4c696b9f15fcd007967974c40f50e819ff70e Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sat, 9 Mar 2019 11:53:13 +0100 Subject: [PATCH 7/9] Fix - A problem with comment handling in import Apparently black and isort do not behave the same. See : https://github.com/ambv/black/issues/251 --- pylint/test/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylint/test/conftest.py b/pylint/test/conftest.py index 985866893d..e2762091da 100644 --- a/pylint/test/conftest.py +++ b/pylint/test/conftest.py @@ -1,11 +1,11 @@ # pylint: disable=redefined-outer-name +# pylint: disable=no-name-in-module import os import pytest from pylint import checkers from pylint.lint import PyLinter -# pylint: disable=no-name-in-module from pylint.testutils import MinimalTestReporter From 5f3491b334d6b4ba24af348c23e609d24c4ecb12 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 10 Mar 2019 21:53:48 +0100 Subject: [PATCH 8/9] Doc - Add isort in the contribution doc --- doc/development_guide/contribute.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/development_guide/contribute.rst b/doc/development_guide/contribute.rst index e74e606e2d..5bf74a17ce 100644 --- a/doc/development_guide/contribute.rst +++ b/doc/development_guide/contribute.rst @@ -95,7 +95,7 @@ your patch gets accepted. pytest pylint -k test_functional - * ``pylint`` uses black_ Python autoformatter for formatting its code. + * ``pylint`` uses black_ and isort_ Python autoformatter for formatting its code. We have a pre-commit hook which should take care of the autoformatting for you for when you are working on a patch. To enable it, do the following: @@ -165,6 +165,7 @@ current environment in order to have faster feedback. Run with:: .. _tox: http://tox.readthedocs.io/en/latest/ .. _pytest: http://pytest.readthedocs.io/en/latest/ .. _black: https://github.com/ambv/black +.. _isort: https://github.com/timothycrosley/isort .. _astroid: https://github.com/pycqa/astroid From 09913f12ba6c05b650b2c3ec1e940a4fabce2a84 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 19 Mar 2019 20:44:59 +0100 Subject: [PATCH 9/9] Feat - Add an isort formatting check in the tox.ini Permit to verify the formatting of future commit. Following review see : https://github.com/PyCQA/pylint/pull/2805#discussion_r266793201 --- .pre-commit-config.yaml | 4 ++-- tox.ini | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e553c91cf..11890aa26b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/ambv/black - rev: 18.9b0 + rev: 19.3b0 hooks: - id: black args: [--safe, --quiet] @@ -12,6 +12,6 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.13 + rev: v4.3.15 hooks: - id: isort diff --git a/tox.ini b/tox.ini index c6ee64354a..b539381d2e 100644 --- a/tox.ini +++ b/tox.ini @@ -12,8 +12,12 @@ commands = pylint -rn --rcfile={toxinidir}/pylintrc --load-plugins=pylint.extens [testenv:formatting] basepython = python3 -deps = black==18.9b0 -commands = black --check --exclude "functional|input|test/extension|test/regrtest_data|test/data" pylint +deps = + black==19.3b0 + isort==4.3.15 +commands = + black --check --exclude "functional|input|test/extension|test/regrtest_data|test/data" pylint + isort -rc pylint/ --check-only changedir = {toxinidir} [testenv:mypy]