diff options
65 files changed, 182 insertions, 286 deletions
diff --git a/astroid/_ast.py b/astroid/_ast.py index 34b74c5f..55e81c68 100644 --- a/astroid/_ast.py +++ b/astroid/_ast.py @@ -1,8 +1,8 @@ import ast +import sys from collections import namedtuple from functools import partial from typing import Optional -import sys import astroid diff --git a/astroid/arguments.py b/astroid/arguments.py index 6de3a533..b9f18e3b 100644 --- a/astroid/arguments.py +++ b/astroid/arguments.py @@ -11,9 +11,7 @@ from astroid import bases from astroid import context as contextmod -from astroid import exceptions -from astroid import nodes -from astroid import util +from astroid import exceptions, nodes, util class CallSite: diff --git a/astroid/bases.py b/astroid/bases.py index c684c25e..05c0ae1c 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -26,8 +26,7 @@ import builtins import collections from astroid import context as contextmod -from astroid import exceptions -from astroid import util +from astroid import exceptions, util objectmodel = util.lazy_import("interpreter.objectmodel") helpers = util.lazy_import("helpers") diff --git a/astroid/brain/brain_argparse.py b/astroid/brain/brain_argparse.py index 6a7556f6..34b551e0 100644 --- a/astroid/brain/brain_argparse.py +++ b/astroid/brain/brain_argparse.py @@ -1,4 +1,4 @@ -from astroid import MANAGER, arguments, nodes, inference_tip, UseInferenceDefault +from astroid import MANAGER, UseInferenceDefault, arguments, inference_tip, nodes def infer_namespace(node, context=None): diff --git a/astroid/brain/brain_attrs.py b/astroid/brain/brain_attrs.py index 54d63d4d..a6cf7387 100644 --- a/astroid/brain/brain_attrs.py +++ b/astroid/brain/brain_attrs.py @@ -10,7 +10,6 @@ for attrs classes import astroid from astroid import MANAGER - ATTRIB_NAMES = frozenset(("attr.ib", "attrib", "attr.attrib")) ATTRS_NAMES = frozenset(("attr.s", "attrs", "attr.attrs", "attr.attributes")) diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index 10847e34..4e3d6e75 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -23,22 +23,21 @@ from functools import partial from astroid import ( MANAGER, - UseInferenceDefault, + AstroidTypeError, AttributeInferenceError, - inference_tip, InferenceError, - NameInferenceError, - AstroidTypeError, MroError, + NameInferenceError, + UseInferenceDefault, + arguments, + helpers, + inference_tip, + nodes, + objects, + scoped_nodes, + util, ) -from astroid import arguments from astroid.builder import AstroidBuilder -from astroid import helpers -from astroid import nodes -from astroid import objects -from astroid import scoped_nodes -from astroid import util - OBJECT_DUNDER_NEW = "object.__new__" diff --git a/astroid/brain/brain_collections.py b/astroid/brain/brain_collections.py index dbeb0441..cb3d4c20 100644 --- a/astroid/brain/brain_collections.py +++ b/astroid/brain/brain_collections.py @@ -12,7 +12,6 @@ import sys import astroid - PY39 = sys.version_info >= (3, 9) diff --git a/astroid/brain/brain_crypt.py b/astroid/brain/brain_crypt.py index 09d4d908..076c1927 100644 --- a/astroid/brain/brain_crypt.py +++ b/astroid/brain/brain_crypt.py @@ -1,6 +1,7 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE import sys + import astroid PY37 = sys.version_info >= (3, 7) diff --git a/astroid/brain/brain_dataclasses.py b/astroid/brain/brain_dataclasses.py index 55c582e2..03045f5e 100644 --- a/astroid/brain/brain_dataclasses.py +++ b/astroid/brain/brain_dataclasses.py @@ -7,7 +7,6 @@ Astroid hook for the dataclasses library import astroid from astroid import MANAGER - DATACLASSES_DECORATORS = frozenset(("dataclasses.dataclass", "dataclass")) diff --git a/astroid/brain/brain_functools.py b/astroid/brain/brain_functools.py index 94f77eb3..705949bd 100644 --- a/astroid/brain/brain_functools.py +++ b/astroid/brain/brain_functools.py @@ -8,14 +8,8 @@ from functools import partial from itertools import chain import astroid -from astroid import arguments -from astroid import BoundMethod -from astroid import extract_node -from astroid import helpers +from astroid import MANAGER, BoundMethod, arguments, extract_node, helpers, objects from astroid.interpreter import objectmodel -from astroid import MANAGER -from astroid import objects - LRU_CACHE = "functools.lru_cache" diff --git a/astroid/brain/brain_gi.py b/astroid/brain/brain_gi.py index ee415e03..cdc195a7 100644 --- a/astroid/brain/brain_gi.py +++ b/astroid/brain/brain_gi.py @@ -23,14 +23,13 @@ Helps with understanding everything imported from 'gi.repository' import inspect import itertools -import sys import re +import sys import warnings from astroid import MANAGER, AstroidBuildingError, nodes from astroid.builder import AstroidBuilder - _inspected_modules = {} _identifier_re = r"^[A-Za-z_]\w*$" diff --git a/astroid/brain/brain_io.py b/astroid/brain/brain_io.py index 99575ab9..b17f67c6 100644 --- a/astroid/brain/brain_io.py +++ b/astroid/brain/brain_io.py @@ -9,7 +9,6 @@ import astroid - BUFFERED = {"BufferedWriter", "BufferedReader"} TextIOWrapper = "TextIOWrapper" FileIO = "FileIO" diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index 69998aa6..c49afa74 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -25,13 +25,17 @@ import functools import keyword from textwrap import dedent -from astroid import MANAGER, UseInferenceDefault, inference_tip, InferenceError -from astroid import arguments -from astroid import exceptions -from astroid import nodes +from astroid import ( + MANAGER, + InferenceError, + UseInferenceDefault, + arguments, + exceptions, + inference_tip, + nodes, + util, +) from astroid.builder import AstroidBuilder, extract_node -from astroid import util - TYPING_NAMEDTUPLE_BASENAMES = {"NamedTuple", "typing.NamedTuple"} ENUM_BASE_NAMES = { diff --git a/astroid/brain/brain_numpy_core_function_base.py b/astroid/brain/brain_numpy_core_function_base.py index 12f94501..1f875798 100644 --- a/astroid/brain/brain_numpy_core_function_base.py +++ b/astroid/brain/brain_numpy_core_function_base.py @@ -9,9 +9,10 @@ """Astroid hooks for numpy.core.function_base module.""" import functools -import astroid -from brain_numpy_utils import looks_like_numpy_member, infer_numpy_member +from brain_numpy_utils import infer_numpy_member, looks_like_numpy_member + +import astroid METHODS_TO_BE_INFERRED = { "linspace": """def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0): diff --git a/astroid/brain/brain_numpy_core_multiarray.py b/astroid/brain/brain_numpy_core_multiarray.py index 8bf47fe1..a33c3a27 100644 --- a/astroid/brain/brain_numpy_core_multiarray.py +++ b/astroid/brain/brain_numpy_core_multiarray.py @@ -8,8 +8,10 @@ """Astroid hooks for numpy.core.multiarray module.""" import functools + +from brain_numpy_utils import infer_numpy_member, looks_like_numpy_member + import astroid -from brain_numpy_utils import looks_like_numpy_member, infer_numpy_member def numpy_core_multiarray_transform(): diff --git a/astroid/brain/brain_numpy_core_numeric.py b/astroid/brain/brain_numpy_core_numeric.py index d8e4fa2a..36c071d5 100644 --- a/astroid/brain/brain_numpy_core_numeric.py +++ b/astroid/brain/brain_numpy_core_numeric.py @@ -9,8 +9,10 @@ """Astroid hooks for numpy.core.numeric module.""" import functools + +from brain_numpy_utils import infer_numpy_member, looks_like_numpy_member + import astroid -from brain_numpy_utils import looks_like_numpy_member, infer_numpy_member def numpy_core_numeric_transform(): diff --git a/astroid/brain/brain_pkg_resources.py b/astroid/brain/brain_pkg_resources.py index c0d0cd84..08b6fc53 100644 --- a/astroid/brain/brain_pkg_resources.py +++ b/astroid/brain/brain_pkg_resources.py @@ -5,9 +5,7 @@ # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -from astroid import parse -from astroid import register_module_extender -from astroid import MANAGER +from astroid import MANAGER, parse, register_module_extender def pkg_resources_transform(): diff --git a/astroid/brain/brain_qt.py b/astroid/brain/brain_qt.py index 40ce4221..9a8fb86c 100644 --- a/astroid/brain/brain_qt.py +++ b/astroid/brain/brain_qt.py @@ -11,10 +11,8 @@ """Astroid hooks for the PyQT library.""" -from astroid import MANAGER, register_module_extender +from astroid import MANAGER, nodes, parse, register_module_extender from astroid.builder import AstroidBuilder -from astroid import nodes -from astroid import parse def _looks_like_signal(node, signal_name="pyqtSignal"): diff --git a/astroid/brain/brain_random.py b/astroid/brain/brain_random.py index 1c0c1eac..ee5506cb 100644 --- a/astroid/brain/brain_random.py +++ b/astroid/brain/brain_random.py @@ -3,9 +3,7 @@ import random import astroid -from astroid import helpers -from astroid import MANAGER - +from astroid import MANAGER, helpers ACCEPTED_ITERABLES_FOR_SAMPLE = (astroid.List, astroid.Set, astroid.Tuple) diff --git a/astroid/brain/brain_re.py b/astroid/brain/brain_re.py index a9e934a6..544191b6 100644 --- a/astroid/brain/brain_re.py +++ b/astroid/brain/brain_re.py @@ -1,8 +1,9 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE import sys + import astroid -from astroid import MANAGER, inference_tip, nodes, context +from astroid import MANAGER, context, inference_tip, nodes PY36 = sys.version_info >= (3, 6) PY37 = sys.version_info[:2] >= (3, 7) diff --git a/astroid/brain/brain_six.py b/astroid/brain/brain_six.py index 7a65855f..3c310cc8 100644 --- a/astroid/brain/brain_six.py +++ b/astroid/brain/brain_six.py @@ -14,15 +14,13 @@ from textwrap import dedent -from astroid import MANAGER, register_module_extender +from astroid import MANAGER, nodes, register_module_extender from astroid.builder import AstroidBuilder from astroid.exceptions import ( AstroidBuildingError, - InferenceError, AttributeInferenceError, + InferenceError, ) -from astroid import nodes - SIX_ADD_METACLASS = "six.add_metaclass" SIX_WITH_METACLASS = "six.with_metaclass" diff --git a/astroid/brain/brain_ssl.py b/astroid/brain/brain_ssl.py index 6c8fd3ee..ddccca94 100644 --- a/astroid/brain/brain_ssl.py +++ b/astroid/brain/brain_ssl.py @@ -9,8 +9,7 @@ """Astroid hooks for the ssl library.""" -from astroid import MANAGER, register_module_extender -from astroid import parse +from astroid import MANAGER, parse, register_module_extender def ssl_transform(): diff --git a/astroid/brain/brain_subprocess.py b/astroid/brain/brain_subprocess.py index 67ce488b..cef1deb8 100644 --- a/astroid/brain/brain_subprocess.py +++ b/astroid/brain/brain_subprocess.py @@ -16,7 +16,6 @@ import textwrap import astroid - PY39 = sys.version_info >= (3, 9) PY37 = sys.version_info >= (3, 7) PY36 = sys.version_info >= (3, 6) diff --git a/astroid/brain/brain_type.py b/astroid/brain/brain_type.py index dada081b..ec4cf2a4 100644 --- a/astroid/brain/brain_type.py +++ b/astroid/brain/brain_type.py @@ -19,7 +19,6 @@ import sys from astroid import MANAGER, extract_node, inference_tip, nodes - PY39 = sys.version_info >= (3, 9) diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py index 41e3ea63..1fb471f1 100644 --- a/astroid/brain/brain_typing.py +++ b/astroid/brain/brain_typing.py @@ -11,18 +11,18 @@ import sys import typing from functools import partial +import astroid from astroid import ( MANAGER, + AttributeInferenceError, + InferenceError, UseInferenceDefault, + context, extract_node, inference_tip, node_classes, nodes, - context, - InferenceError, - AttributeInferenceError, ) -import astroid PY37 = sys.version_info[:2] >= (3, 7) PY39 = sys.version_info[:2] >= (3, 9) diff --git a/astroid/brain/brain_uuid.py b/astroid/brain/brain_uuid.py index 0a3f39b1..257379de 100644 --- a/astroid/brain/brain_uuid.py +++ b/astroid/brain/brain_uuid.py @@ -8,8 +8,7 @@ """Astroid hooks for the UUID module.""" -from astroid import MANAGER -from astroid import nodes +from astroid import MANAGER, nodes def _patch_uuid_class(node): diff --git a/astroid/builder.py b/astroid/builder.py index 0e7a11a9..789c2c0a 100644 --- a/astroid/builder.py +++ b/astroid/builder.py @@ -23,15 +23,17 @@ import os import textwrap from tokenize import detect_encoding +from astroid import ( + bases, + exceptions, + manager, + modutils, + nodes, + raw_building, + rebuilder, + util, +) from astroid._ast import get_parser_module -from astroid import bases -from astroid import exceptions -from astroid import manager -from astroid import modutils -from astroid import raw_building -from astroid import rebuilder -from astroid import nodes -from astroid import util objects = util.lazy_import("objects") diff --git a/astroid/decorators.py b/astroid/decorators.py index 5eb88e9c..dc41d602 100644 --- a/astroid/decorators.py +++ b/astroid/decorators.py @@ -22,8 +22,7 @@ import functools import wrapt from astroid import context as contextmod -from astroid import exceptions -from astroid import util +from astroid import exceptions, util @wrapt.decorator diff --git a/astroid/helpers.py b/astroid/helpers.py index 73050995..cb16ecdc 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -19,13 +19,7 @@ import builtins as builtins_mod from astroid import bases from astroid import context as contextmod -from astroid import exceptions -from astroid import manager -from astroid import nodes -from astroid import raw_building -from astroid import scoped_nodes -from astroid import util - +from astroid import exceptions, manager, nodes, raw_building, scoped_nodes, util BUILTINS = builtins_mod.__name__ diff --git a/astroid/inference.py b/astroid/inference.py index 82d93f29..9c800fa8 100644 --- a/astroid/inference.py +++ b/astroid/inference.py @@ -30,17 +30,11 @@ import itertools import operator import wrapt + from astroid import bases from astroid import context as contextmod -from astroid import exceptions -from astroid import decorators -from astroid import helpers -from astroid import manager -from astroid import nodes +from astroid import decorators, exceptions, helpers, manager, nodes, protocols, util from astroid.interpreter import dunder_lookup -from astroid import protocols -from astroid import util - MANAGER = manager.AstroidManager() # Prevents circular imports diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py index bc6d9eae..eac74a23 100644 --- a/astroid/interpreter/_import/spec.py +++ b/astroid/interpreter/_import/spec.py @@ -17,12 +17,11 @@ import abc import collections import distutils import enum +import importlib.machinery import os import sys import zipimport -import importlib.machinery - try: from functools import lru_cache except ImportError: diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py index 032e7d13..dc6cc31b 100644 --- a/astroid/interpreter/objectmodel.py +++ b/astroid/interpreter/objectmodel.py @@ -30,17 +30,15 @@ mechanism. """ import itertools -import pprint import os +import pprint import types from functools import lru_cache from typing import Optional import astroid from astroid import context as contextmod -from astroid import exceptions -from astroid import node_classes -from astroid import util +from astroid import exceptions, node_classes, util # Prevents circular imports objects = util.lazy_import("objects") @@ -473,8 +471,7 @@ class ClassModel(ObjectModel): thus it might miss a couple of them. """ # pylint: disable=import-outside-toplevel; circular import - from astroid import bases - from astroid import scoped_nodes + from astroid import bases, scoped_nodes if not self._instance.newstyle: raise exceptions.AttributeInferenceError( diff --git a/astroid/manager.py b/astroid/manager.py index 1c56f8be..6903e0ab 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -26,11 +26,8 @@ from various source and using a cache of built modules) import os import zipimport -from astroid import exceptions +from astroid import exceptions, modutils, transforms from astroid.interpreter._import import spec -from astroid import modutils -from astroid import transforms - ZIP_IMPORT_EXTS = (".zip", ".egg", ".whl") diff --git a/astroid/mixins.py b/astroid/mixins.py index feb8c08f..7ad8775b 100644 --- a/astroid/mixins.py +++ b/astroid/mixins.py @@ -16,8 +16,7 @@ """ import itertools -from astroid import decorators -from astroid import exceptions +from astroid import decorators, exceptions class BlockRangeMixIn: diff --git a/astroid/modutils.py b/astroid/modutils.py index ae3163dc..181891d4 100644 --- a/astroid/modutils.py +++ b/astroid/modutils.py @@ -34,21 +34,21 @@ :var BUILTIN_MODULES: dictionary with builtin module names has key """ import importlib.util +import itertools import os import platform import sys -import itertools -from distutils.sysconfig import get_python_lib # pylint: disable=import-error # pylint: disable=import-error, no-name-in-module from distutils.errors import DistutilsPlatformError +from distutils.sysconfig import get_python_lib # pylint: disable=import-error + +from .interpreter._import import spec, util # distutils is replaced by virtualenv with a module that does # weird path manipulations in order to get to the # real distutils module. -from .interpreter._import import spec -from .interpreter._import import util if sys.platform.startswith("win"): PY_SOURCE_EXTS = ("py", "pyw") diff --git a/astroid/node_classes.py b/astroid/node_classes.py index f1431ef4..8d547e53 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -39,17 +39,12 @@ import builtins as builtins_mod import itertools import pprint import sys -from functools import lru_cache, singledispatch as _singledispatch +from functools import lru_cache +from functools import singledispatch as _singledispatch -from astroid import as_string -from astroid import bases +from astroid import as_string, bases from astroid import context as contextmod -from astroid import decorators -from astroid import exceptions -from astroid import manager -from astroid import mixins -from astroid import util - +from astroid import decorators, exceptions, manager, mixins, util BUILTINS = builtins_mod.__name__ MANAGER = manager.AstroidManager() diff --git a/astroid/nodes.py b/astroid/nodes.py index 8a6f1ebf..adcf7596 100644 --- a/astroid/nodes.py +++ b/astroid/nodes.py @@ -20,15 +20,18 @@ All nodes inherit from :class:`~astroid.node_classes.NodeNG`. """ # pylint: disable=unused-import,redefined-builtin -from astroid.node_classes import ( +from astroid.node_classes import ( # Node not present in the builtin ast module. + AnnAssign, Arguments, - AssignAttr, Assert, Assign, - AnnAssign, + AssignAttr, AssignName, + AsyncFor, + AsyncWith, + Attribute, AugAssign, - Repr, + Await, BinOp, BoolOp, Break, @@ -39,23 +42,26 @@ from astroid.node_classes import ( Continue, Decorators, DelAttr, - DelName, Delete, + DelName, Dict, - Expr, + DictUnpack, Ellipsis, EmptyNode, + EvaluatedObject, ExceptHandler, Exec, + Expr, ExtSlice, For, - ImportFrom, - Attribute, + FormattedValue, Global, If, IfExp, Import, + ImportFrom, Index, + JoinedStr, Keyword, List, Name, @@ -64,6 +70,7 @@ from astroid.node_classes import ( Pass, Print, Raise, + Repr, Return, Set, Slice, @@ -73,34 +80,25 @@ from astroid.node_classes import ( TryFinally, Tuple, UnaryOp, + Unknown, While, With, Yield, YieldFrom, const_factory, - AsyncFor, - Await, - AsyncWith, - FormattedValue, - JoinedStr, - # Node not present in the builtin ast module. - DictUnpack, - Unknown, - EvaluatedObject, ) from astroid.scoped_nodes import ( - Module, + AsyncFunctionDef, + ClassDef, + DictComp, + FunctionDef, GeneratorExp, Lambda, - DictComp, ListComp, + Module, SetComp, - FunctionDef, - ClassDef, - AsyncFunctionDef, ) - ALL_NODE_CLASSES = ( AsyncFunctionDef, AsyncFor, diff --git a/astroid/objects.py b/astroid/objects.py index e1f50d51..f07b41fa 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -20,14 +20,15 @@ leads to an inferred FrozenSet: import builtins -from astroid import bases -from astroid import decorators -from astroid import exceptions -from astroid import MANAGER -from astroid import node_classes -from astroid import scoped_nodes -from astroid import util - +from astroid import ( + MANAGER, + bases, + decorators, + exceptions, + node_classes, + scoped_nodes, + util, +) BUILTINS = builtins.__name__ objectmodel = util.lazy_import("interpreter.objectmodel") diff --git a/astroid/protocols.py b/astroid/protocols.py index 6d10582c..b4c44444 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -26,20 +26,12 @@ where it makes sense. """ import collections -import operator as operator_mod - import itertools +import operator as operator_mod -from astroid import Store -from astroid import arguments -from astroid import bases +from astroid import Store, arguments, bases from astroid import context as contextmod -from astroid import exceptions -from astroid import decorators -from astroid import node_classes -from astroid import helpers -from astroid import nodes -from astroid import util +from astroid import decorators, exceptions, helpers, node_classes, nodes, util raw_building = util.lazy_import("raw_building") objects = util.lazy_import("objects") diff --git a/astroid/raw_building.py b/astroid/raw_building.py index 3dbc7019..58a81964 100644 --- a/astroid/raw_building.py +++ b/astroid/raw_building.py @@ -30,11 +30,7 @@ import sys import types import warnings -from astroid import bases -from astroid import manager -from astroid import node_classes -from astroid import nodes - +from astroid import bases, manager, node_classes, nodes MANAGER = manager.AstroidManager() # the keys of CONST_CLS eg python builtin types diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index 924854b9..36995ec1 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -31,9 +31,8 @@ import sys from typing import Optional import astroid -from astroid._ast import parse_function_type_comment, get_parser_module, ParserModule from astroid import nodes - +from astroid._ast import ParserModule, get_parser_module, parse_function_type_comment CONST_NAME_TRANSFORMS = {"None": None, "True": True, "False": False} diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index 403b50a0..431e6c0f 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -37,22 +37,16 @@ Lambda, GeneratorExp, DictComp and SetComp to some extent). """ import builtins -import sys import io import itertools -from typing import Optional, List +import sys +from typing import List, Optional from astroid import bases from astroid import context as contextmod -from astroid import exceptions from astroid import decorators as decorators_mod -from astroid.interpreter import objectmodel -from astroid.interpreter import dunder_lookup -from astroid import manager -from astroid import mixins -from astroid import node_classes -from astroid import util - +from astroid import exceptions, manager, mixins, node_classes, util +from astroid.interpreter import dunder_lookup, objectmodel PY39 = sys.version_info[:2] >= (3, 9) diff --git a/astroid/util.py b/astroid/util.py index 19981363..8cbdc810 100644 --- a/astroid/util.py +++ b/astroid/util.py @@ -9,9 +9,9 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE +import importlib import warnings -import importlib import lazy_object_proxy @@ -3,3 +3,11 @@ test = pytest [tool:pytest] testpaths = tests + +[isort] +multi_line_output = 3 +line_length = 88 +known_third_party = sphinx, isort, pytest, mccabe, six, toml +include_trailing_comma = True +skip_glob = tests/testdata +src_paths = astroid diff --git a/tests/resources.py b/tests/resources.py index 869b66af..20adc2f8 100644 --- a/tests/resources.py +++ b/tests/resources.py @@ -13,11 +13,9 @@ import os import sys -from astroid import builder -from astroid import MANAGER +from astroid import MANAGER, builder from astroid.bases import BUILTINS - DATA_DIR = os.path.join("testdata", "python3") RESOURCE_PATH = os.path.join(os.path.dirname(__file__), DATA_DIR, "data") diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py index f7e72ca6..63084355 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -33,9 +33,9 @@ """Tests for basic functionality in astroid.brain.""" import io +import os import queue import re -import os try: import multiprocessing # pylint: disable=unused-import @@ -76,13 +76,9 @@ try: except ImportError: HAS_SIX = False -from astroid import MANAGER -from astroid import bases -from astroid import builder -from astroid import nodes -from astroid import util import astroid import astroid.test_utils as test_utils +from astroid import MANAGER, bases, builder, nodes, util def assertEqualMro(klass, expected_mro): diff --git a/tests/unittest_brain_numpy_core_numerictypes.py b/tests/unittest_brain_numpy_core_numerictypes.py index 6037bf96..bc23eb1b 100644 --- a/tests/unittest_brain_numpy_core_numerictypes.py +++ b/tests/unittest_brain_numpy_core_numerictypes.py @@ -15,8 +15,7 @@ try: except ImportError: HAS_NUMPY = False -from astroid import builder -from astroid import nodes +from astroid import builder, nodes @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") diff --git a/tests/unittest_brain_numpy_core_umath.py b/tests/unittest_brain_numpy_core_umath.py index adee545a..12c1e3bb 100644 --- a/tests/unittest_brain_numpy_core_umath.py +++ b/tests/unittest_brain_numpy_core_umath.py @@ -14,9 +14,7 @@ try: except ImportError: HAS_NUMPY = False -from astroid import builder -from astroid import nodes, bases -from astroid import util +from astroid import bases, builder, nodes, util @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") diff --git a/tests/unittest_brain_numpy_random_mtrand.py b/tests/unittest_brain_numpy_random_mtrand.py index 0bc1a67c..c0b7200b 100644 --- a/tests/unittest_brain_numpy_random_mtrand.py +++ b/tests/unittest_brain_numpy_random_mtrand.py @@ -14,8 +14,7 @@ try: except ImportError: HAS_NUMPY = False -from astroid import builder -from astroid import nodes +from astroid import builder, nodes @unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.") diff --git a/tests/unittest_builder.py b/tests/unittest_builder.py index 4e0a8925..a48d3419 100644 --- a/tests/unittest_builder.py +++ b/tests/unittest_builder.py @@ -27,12 +27,9 @@ import sys import unittest import pytest -from astroid import builder -from astroid import exceptions -from astroid import manager -from astroid import nodes -from astroid import test_utils -from astroid import util + +from astroid import builder, exceptions, manager, nodes, test_utils, util + from . import resources MANAGER = manager.AstroidManager() diff --git a/tests/unittest_helpers.py b/tests/unittest_helpers.py index 5cc20d55..35379c67 100644 --- a/tests/unittest_helpers.py +++ b/tests/unittest_helpers.py @@ -9,15 +9,10 @@ # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -import unittest import builtins +import unittest -from astroid import builder -from astroid import exceptions -from astroid import helpers -from astroid import manager -from astroid import raw_building -from astroid import util +from astroid import builder, exceptions, helpers, manager, raw_building, util class TestHelpers(unittest.TestCase): diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index 329c78e8..1889ba1b 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -37,25 +37,20 @@ """ # pylint: disable=too-many-lines import platform +import sys import textwrap -from functools import partial import unittest +from functools import partial from unittest.mock import patch import pytest -import sys -from astroid import InferenceError, builder, nodes, Slice -from astroid.builder import parse, extract_node -from astroid.inference import infer_end as inference_infer_end -from astroid.bases import Instance, BoundMethod, UnboundMethod, BUILTINS -from astroid import arguments +from astroid import InferenceError, Slice, arguments, builder from astroid import decorators as decoratorsmod -from astroid import exceptions -from astroid import helpers -from astroid import objects -from astroid import test_utils -from astroid import util +from astroid import exceptions, helpers, nodes, objects, test_utils, util +from astroid.bases import BUILTINS, BoundMethod, Instance, UnboundMethod +from astroid.builder import extract_node, parse +from astroid.inference import infer_end as inference_infer_end from astroid.objects import ExceptionInstance from . import resources diff --git a/tests/unittest_lookup.py b/tests/unittest_lookup.py index a03b581b..82ef8837 100644 --- a/tests/unittest_lookup.py +++ b/tests/unittest_lookup.py @@ -16,10 +16,8 @@ import functools import unittest -from astroid import builder -from astroid import exceptions -from astroid import nodes -from astroid import scoped_nodes +from astroid import builder, exceptions, nodes, scoped_nodes + from . import resources diff --git a/tests/unittest_manager.py b/tests/unittest_manager.py index 73b9379a..4d1eadd6 100644 --- a/tests/unittest_manager.py +++ b/tests/unittest_manager.py @@ -23,16 +23,15 @@ import os import platform import site import sys +import time import unittest import pkg_resources -import time import astroid -from astroid import exceptions -from astroid import manager -from . import resources +from astroid import exceptions, manager +from . import resources BUILTINS = builtins.__name__ diff --git a/tests/unittest_modutils.py b/tests/unittest_modutils.py index 3a337ba7..a4f3e908 100644 --- a/tests/unittest_modutils.py +++ b/tests/unittest_modutils.py @@ -23,17 +23,18 @@ unit tests for module modutils (module manipulation utilities) import distutils.version import email import os +import shutil import sys +import tempfile import unittest import xml from xml import etree from xml.etree import ElementTree -import tempfile -import shutil import astroid -from astroid.interpreter._import import spec from astroid import modutils +from astroid.interpreter._import import spec + from . import resources diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py index fb9ffc25..46790ed0 100644 --- a/tests/unittest_nodes.py +++ b/tests/unittest_nodes.py @@ -26,28 +26,21 @@ """tests for specific behaviour of astroid nodes """ import builtins +import copy import os +import platform import sys import textwrap import unittest -import copy -import platform import pytest import astroid -from astroid import bases -from astroid import builder +from astroid import bases, builder from astroid import context as contextmod -from astroid import exceptions -from astroid import node_classes -from astroid import nodes -from astroid import parse -from astroid import util -from astroid import test_utils -from astroid import transforms -from . import resources +from astroid import exceptions, node_classes, nodes, parse, test_utils, transforms, util +from . import resources abuilder = builder.AstroidBuilder() BUILTINS = builtins.__name__ diff --git a/tests/unittest_object_model.py b/tests/unittest_object_model.py index 8b1c1b3a..5d438a65 100644 --- a/tests/unittest_object_model.py +++ b/tests/unittest_object_model.py @@ -16,12 +16,7 @@ import xml import pytest import astroid -from astroid import builder, util -from astroid import exceptions -from astroid import MANAGER -from astroid import test_utils -from astroid import objects - +from astroid import MANAGER, builder, exceptions, objects, test_utils, util BUILTINS = MANAGER.astroid_cache[builtins.__name__] diff --git a/tests/unittest_objects.py b/tests/unittest_objects.py index b2512afd..4aa21ece 100644 --- a/tests/unittest_objects.py +++ b/tests/unittest_objects.py @@ -12,11 +12,7 @@ import unittest -from astroid import bases -from astroid import builder -from astroid import exceptions -from astroid import nodes -from astroid import objects +from astroid import bases, builder, exceptions, nodes, objects class ObjectsTest(unittest.TestCase): diff --git a/tests/unittest_protocols.py b/tests/unittest_protocols.py index febccc0e..b797f022 100644 --- a/tests/unittest_protocols.py +++ b/tests/unittest_protocols.py @@ -13,16 +13,13 @@ import contextlib +import sys import unittest import pytest -import sys import astroid -from astroid import extract_node -from astroid import InferenceError -from astroid import nodes -from astroid import util +from astroid import InferenceError, extract_node, nodes, util from astroid.node_classes import AssignName, Const, Name, Starred diff --git a/tests/unittest_python3.py b/tests/unittest_python3.py index b6289adf..14317df4 100644 --- a/tests/unittest_python3.py +++ b/tests/unittest_python3.py @@ -14,12 +14,12 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE -from textwrap import dedent import unittest +from textwrap import dedent from astroid import nodes -from astroid.node_classes import Assign, Expr, YieldFrom, Name, Const from astroid.builder import AstroidBuilder, extract_node +from astroid.node_classes import Assign, Const, Expr, Name, YieldFrom from astroid.scoped_nodes import ClassDef, FunctionDef from astroid.test_utils import require_version diff --git a/tests/unittest_raw_building.py b/tests/unittest_raw_building.py index 2b27a64d..a640d940 100644 --- a/tests/unittest_raw_building.py +++ b/tests/unittest_raw_building.py @@ -16,13 +16,14 @@ import platform import unittest import _io + from astroid.builder import AstroidBuilder from astroid.raw_building import ( attach_dummy_node, - build_module, build_class, - build_function, build_from_import, + build_function, + build_module, ) diff --git a/tests/unittest_regrtest.py b/tests/unittest_regrtest.py index cc2e4e48..29febfb8 100644 --- a/tests/unittest_regrtest.py +++ b/tests/unittest_regrtest.py @@ -16,16 +16,15 @@ # For details: https://github.com/PyCQA/astroid/blob/master/LICENSE import sys -import unittest import textwrap +import unittest -from astroid import MANAGER, Instance, nodes +from astroid import MANAGER, Instance, exceptions, nodes, transforms from astroid.bases import BUILTINS from astroid.builder import AstroidBuilder, extract_node -from astroid import exceptions -from astroid.raw_building import build_module from astroid.manager import AstroidManager -from astroid import transforms +from astroid.raw_building import build_module + from . import resources try: diff --git a/tests/unittest_scoped_nodes.py b/tests/unittest_scoped_nodes.py index d8855718..2eb43871 100644 --- a/tests/unittest_scoped_nodes.py +++ b/tests/unittest_scoped_nodes.py @@ -33,27 +33,25 @@ import datetime import os import sys import textwrap -from functools import partial import unittest +from functools import partial import pytest -from astroid import builder, objects -from astroid import nodes -from astroid import scoped_nodes -from astroid import util + +from astroid import builder, nodes, objects, scoped_nodes, test_utils, util +from astroid.bases import BUILTINS, BoundMethod, Generator, Instance, UnboundMethod from astroid.exceptions import ( - InferenceError, AttributeInferenceError, + DuplicateBasesError, + InconsistentMroError, + InferenceError, + MroError, + NameInferenceError, NoDefault, ResolveError, - MroError, - InconsistentMroError, - DuplicateBasesError, TooManyLevelsError, - NameInferenceError, ) -from astroid.bases import BUILTINS, Instance, BoundMethod, UnboundMethod, Generator -from astroid import test_utils + from . import resources try: diff --git a/tests/unittest_transforms.py b/tests/unittest_transforms.py index a5920c55..c3723941 100644 --- a/tests/unittest_transforms.py +++ b/tests/unittest_transforms.py @@ -14,10 +14,7 @@ import contextlib import time import unittest -from astroid import builder -from astroid import nodes -from astroid import parse -from astroid import transforms +from astroid import builder, nodes, parse, transforms @contextlib.contextmanager diff --git a/tests/unittest_utils.py b/tests/unittest_utils.py index 09bb7084..af65cac2 100644 --- a/tests/unittest_utils.py +++ b/tests/unittest_utils.py @@ -12,10 +12,7 @@ import unittest -from astroid import builder -from astroid import InferenceError -from astroid import nodes -from astroid import node_classes +from astroid import InferenceError, builder, node_classes, nodes from astroid import util as astroid_util |