diff options
-rw-r--r-- | astroid/__init__.py | 5 | ||||
-rw-r--r-- | astroid/bases.py | 5 | ||||
-rw-r--r-- | astroid/builder.py | 5 | ||||
-rw-r--r-- | astroid/decorators.py | 5 | ||||
-rw-r--r-- | astroid/exceptions.py | 6 | ||||
-rw-r--r-- | astroid/interpreter/_import/spec.py | 25 | ||||
-rw-r--r-- | astroid/interpreter/objectmodel.py | 14 | ||||
-rw-r--r-- | astroid/manager.py | 8 | ||||
-rw-r--r-- | astroid/modutils.py | 11 | ||||
-rw-r--r-- | astroid/node_classes.py | 17 | ||||
-rw-r--r-- | astroid/objects.py | 3 | ||||
-rw-r--r-- | astroid/protocols.py | 8 | ||||
-rw-r--r-- | astroid/raw_building.py | 5 | ||||
-rw-r--r-- | astroid/rebuilder.py | 2 | ||||
-rw-r--r-- | astroid/scoped_nodes.py | 4 | ||||
-rw-r--r-- | astroid/tests/unittest_object_model.py | 1 | ||||
-rw-r--r-- | pylintrc | 3 | ||||
-rw-r--r-- | tox.ini | 1 |
18 files changed, 73 insertions, 55 deletions
diff --git a/astroid/__init__.py b/astroid/__init__.py index e7e8d948..69b2ff0c 100644 --- a/astroid/__init__.py +++ b/astroid/__init__.py @@ -39,7 +39,6 @@ import enum _Context = enum.Enum('Context', 'Load Store Del') -# pylint: disable=no-member; github.com/pycqa/pylint/issues/690 Load = _Context.Load Store = _Context.Store Del = _Context.Del @@ -50,8 +49,6 @@ from .__pkginfo__ import version as __version__ # WARNING: internal imports order matters ! # pylint: disable=redefined-builtin, wildcard-import -# pylint: disable=wrong-import-position; the current order of imports is critical -# here, that's why we don't respect it. # make all exception classes accessible from astroid package from astroid.exceptions import * @@ -96,8 +93,8 @@ class AsStringRegexpPredicate(object): def __call__(self, node): if self.expression is not None: - # pylint: disable=no-member; github.com/pycqa/astroid/126 node = attrgetter(self.expression)(node) + # pylint: disable=no-member; github.com/pycqa/astroid/126 return self.regexp.search(node.as_string()) def inference_tip(infer_function): diff --git a/astroid/bases.py b/astroid/bases.py index 4fc79598..a66dddbb 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -220,6 +220,7 @@ class BaseInstance(Proxy): class Instance(BaseInstance): """A special node representing a class instance.""" + # pylint: disable=unnecessary-lambda special_attributes = util.lazy_descriptor(lambda: objectmodel.InstanceModel()) def __repr__(self): @@ -278,6 +279,7 @@ class Instance(BaseInstance): class UnboundMethod(Proxy): """a special node representing a method not bound to an instance""" + # pylint: disable=unnecessary-lambda special_attributes = util.lazy_descriptor(lambda: objectmodel.UnboundMethodModel()) def __repr__(self): @@ -315,6 +317,7 @@ class UnboundMethod(Proxy): class BoundMethod(UnboundMethod): """a special node representing a method bound to an instance""" + # pylint: disable=unnecessary-lambda special_attributes = util.lazy_descriptor(lambda: objectmodel.BoundMethodModel()) def __init__(self, proxy, bound): @@ -420,8 +423,10 @@ class Generator(BaseInstance): Proxied class is set once for all in raw_building. """ + # pylint: disable=unnecessary-lambda special_attributes = util.lazy_descriptor(lambda: objectmodel.GeneratorModel()) + # pylint: disable=super-init-not-called def __init__(self, parent=None): self.parent = parent diff --git a/astroid/builder.py b/astroid/builder.py index a279ff8e..5304aa95 100644 --- a/astroid/builder.py +++ b/astroid/builder.py @@ -12,11 +12,11 @@ The builder is not thread safe and can't be used to parse different sources at the same time. """ -import _ast import re import os import sys import textwrap +import _ast from astroid import bases from astroid import exceptions @@ -42,9 +42,6 @@ def _parse(string): if sys.version_info >= (3, 0): - # pylint: disable=no-name-in-module; We don't understand flows yet. - # pylint: disable=wrong-import-order, wrong-import-position; have to do it here, - # rather than moving the entire block between standard and local imports. from tokenize import detect_encoding def open_source_file(filename): diff --git a/astroid/decorators.py b/astroid/decorators.py index 1d31bb60..a59cab22 100644 --- a/astroid/decorators.py +++ b/astroid/decorators.py @@ -94,7 +94,7 @@ def path_wrapper(func): except StopIteration as error: # Explicit StopIteration to return error information, see # comment in raise_if_nothing_inferred. - if len(error.args) > 0: + if error.args: raise StopIteration(error.args[0]) else: raise StopIteration @@ -139,7 +139,8 @@ def raise_if_nothing_inferred(func, instance, args, kwargs): inferred = True except StopIteration as error: if not inferred: - if len(error.args) > 0: + if error.args: + # pylint: disable=not-a-mapping raise exceptions.InferenceError(**error.args[0]) else: raise exceptions.InferenceError( diff --git a/astroid/exceptions.py b/astroid/exceptions.py index bb05bc04..ea2b9b07 100644 --- a/astroid/exceptions.py +++ b/astroid/exceptions.py @@ -42,6 +42,7 @@ class AstroidBuildingError(AstroidError): error: Exception raised during construction. """ + # pylint: disable=useless-super-delegation; https://github.com/PyCQA/pylint/issues/1085 def __init__(self, message='Failed to import module {modname}.', **kws): super(AstroidBuildingError, self).__init__(message, **kws) @@ -60,6 +61,7 @@ class TooManyLevelsError(AstroidImportError): level = None name = None + # pylint: disable=useless-super-delegation; https://github.com/PyCQA/pylint/issues/1085 def __init__(self, message='Relative import with too many levels ' '({level}) for module {name!r}', **kws): super(TooManyLevelsError, self).__init__(message, **kws) @@ -80,6 +82,7 @@ class NoDefault(AstroidError): func = None name = None + # pylint: disable=useless-super-delegation; https://github.com/PyCQA/pylint/issues/1085 def __init__(self, message='{func!r} has no default for {name!r}.', **kws): super(NoDefault, self).__init__(message, **kws) @@ -144,6 +147,7 @@ class InferenceError(ResolveError): node = None context = None + # pylint: disable=useless-super-delegation; https://github.com/PyCQA/pylint/issues/1085 def __init__(self, message='Inference failed for {node!r}.', **kws): super(InferenceError, self).__init__(message, **kws) @@ -161,6 +165,7 @@ class NameInferenceError(InferenceError): name = None scope = None + # pylint: disable=useless-super-delegation; https://github.com/PyCQA/pylint/issues/1085 def __init__(self, message='{name!r} not found in {scope!r}.', **kws): super(NameInferenceError, self).__init__(message, **kws) @@ -176,6 +181,7 @@ class AttributeInferenceError(ResolveError): target = None attribute = None + # pylint: disable=useless-super-delegation; https://github.com/PyCQA/pylint/issues/1085 def __init__(self, message='{attribute!r} not found on {target!r}.', **kws): super(AttributeInferenceError, self).__init__(message, **kws) diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py index 001acb3a..97654fab 100644 --- a/astroid/interpreter/_import/spec.py +++ b/astroid/interpreter/_import/spec.py @@ -24,7 +24,7 @@ _ImpTypes = {imp.C_BUILTIN: ModuleType.C_BUILTIN, imp.PY_COMPILED: ModuleType.PY_COMPILED, imp.PY_FROZEN: ModuleType.PY_FROZEN, imp.PY_SOURCE: ModuleType.PY_SOURCE, - } + } if hasattr(imp, 'PY_RESOURCE'): _ImpTypes[imp.PY_RESOURCE] = ModuleType.PY_RESOURCE if hasattr(imp, 'PY_CODERESOURCE'): @@ -43,9 +43,9 @@ class ModuleSpec(_ModuleSpec): and where submodules can be found, if the module is a package. """ - def __new__(cls, name, type, location=None, origin=None, + def __new__(cls, name, module_type, location=None, origin=None, submodule_search_locations=None): - return _ModuleSpec.__new__(cls, name=name, type=type, + return _ModuleSpec.__new__(cls, name=name, type=module_type, location=location, origin=origin, submodule_search_locations=submodule_search_locations) @@ -75,14 +75,14 @@ class Finder(object): None, otherwise. """ - def contribute_to_path(self, filename, processed): + def contribute_to_path(self, spec, processed): """Get a list of extra paths where this finder can search.""" class ImpFinder(Finder): """A finder based on the imp module.""" - def find_module(self, modname, _, processed, submodule_path): + def find_module(self, modname, module_parts, processed, submodule_path): try: stream, mp_filename, mp_desc = imp.find_module(modname, submodule_path) except ImportError: @@ -93,7 +93,7 @@ class ImpFinder(Finder): stream.close() return ModuleSpec(name=modname, location=mp_filename, - type=_imp_type_to_module_type(mp_desc[2])) + module_type=_imp_type_to_module_type(mp_desc[2])) def contribute_to_path(self, spec, processed): if spec.location is None: @@ -118,7 +118,7 @@ class ExplicitNamespacePackageFinder(ImpFinder): submodule_path = sys.modules[modname].__path__ return ModuleSpec(name=modname, location='', origin='namespace', - type=ModuleType.PY_NAMESPACE, + module_type=ModuleType.PY_NAMESPACE, submodule_search_locations=submodule_path) @@ -140,7 +140,7 @@ class ZipFinder(Finder): return None return ModuleSpec(name=modname, location=filename, - origin='egg', type=file_type, + origin='egg', module_type=file_type, submodule_search_locations=path) @@ -151,10 +151,11 @@ class PathSpecFinder(Finder): spec = importlib.machinery.PathFinder.find_spec(modname, path=submodule_path) if spec: location = spec.origin if spec.origin != 'namespace' else None - type = ModuleType.PY_NAMESPACE if spec.origin == 'namespace' else None + module_type = ModuleType.PY_NAMESPACE if spec.origin == 'namespace' else None spec = ModuleSpec(name=spec.name, location=location, - origin=spec.origin, type=type, - submodule_search_locations=list(spec.submodule_search_locations or [])) + origin=spec.origin, module_type=module_type, + submodule_search_locations=list(spec.submodule_search_locations + or [])) return spec def contribute_to_path(self, spec, processed): @@ -257,7 +258,7 @@ def find_spec(modpath, path=None): submodule_path or path) processed.append(modname) if modpath: - submodule_path = finder.contribute_to_path(spec, processed) + submodule_path = finder.contribute_to_path(spec, processed) if spec.type == ModuleType.PKG_DIRECTORY: spec = spec._replace(submodule_search_locations=submodule_path) diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py index 613df836..f61c6654 100644 --- a/astroid/interpreter/objectmodel.py +++ b/astroid/interpreter/objectmodel.py @@ -50,6 +50,9 @@ def _dunder_dict(instance, attributes): class ObjectModel(object): + def __init__(self): + self._instance = None + def __repr__(self): result = [] cname = type(self).__name__ @@ -291,6 +294,7 @@ class FunctionModel(ObjectModel): new_func = func.__class__(name=func.name, doc=func.doc, lineno=func.lineno, col_offset=func.col_offset, parent=cls) + # pylint: disable=no-member new_func.postinit(func.args, func.body, func.decorators, func.returns) @@ -487,18 +491,18 @@ class BoundMethodModel(FunctionModel): class GeneratorModel(FunctionModel): - def __new__(self, *args, **kwargs): + def __new__(cls, *args, **kwargs): # Append the values from the GeneratorType unto this object. - cls = super(GeneratorModel, self).__new__(self, *args, **kwargs) + ret = super(GeneratorModel, cls).__new__(cls, *args, **kwargs) generator = astroid.MANAGER.astroid_cache[six.moves.builtins.__name__]['generator'] for name, values in generator.locals.items(): print(name, values) method = values[0] - patched = lambda self, meth=method: meth + patched = lambda cls, meth=method: meth - setattr(type(cls), 'py' + name, property(patched)) + setattr(type(ret), 'py' + name, property(patched)) - return cls + return ret @property def py__name__(self): diff --git a/astroid/manager.py b/astroid/manager.py index 05512200..8b049092 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -112,13 +112,16 @@ class AstroidManager(object): os.chdir(os.path.dirname(context_file)) try: found_spec = self.file_from_module_name(modname, context_file) + # pylint: disable=no-member if found_spec.type == spec.ModuleType.PY_ZIPMODULE: + # pylint: disable=no-member module = self.zip_import_data(found_spec.location) if module is not None: return module elif found_spec.type in (spec.ModuleType.C_BUILTIN, spec.ModuleType.C_EXTENSION): + # pylint: disable=no-member if (found_spec.type == spec.ModuleType.C_EXTENSION and not self._can_load_extension(modname)): return self._build_stub_module(modname) @@ -133,17 +136,21 @@ class AstroidManager(object): elif found_spec.type == spec.ModuleType.PY_COMPILED: raise exceptions.AstroidImportError( "Unable to load compiled module {modname}.", + # pylint: disable=no-member modname=modname, path=found_spec.location) elif found_spec.type == spec.ModuleType.PY_NAMESPACE: return self._build_namespace_module(modname, + # pylint: disable=no-member found_spec.submodule_search_locations) + # pylint: disable=no-member if found_spec.location is None: raise exceptions.AstroidImportError( "Can't find a file for module {modname}.", modname=modname) + # pylint: disable=no-member return self.ast_from_file(found_spec.location, modname, fallback=False) except exceptions.AstroidBuildingError as e: for hook in self._failed_import_hooks: @@ -151,6 +158,7 @@ class AstroidManager(object): return hook(modname) except exceptions.AstroidBuildingError: pass + # pylint: disable=raising-bad-type; https://github.com/PyCQA/pylint/issues/157 raise e finally: os.chdir(old_cwd) diff --git a/astroid/modutils.py b/astroid/modutils.py index eb7673a6..f17bfdab 100644 --- a/astroid/modutils.py +++ b/astroid/modutils.py @@ -26,15 +26,10 @@ import sys from distutils.sysconfig import get_python_lib # pylint: disable=import-error # pylint: disable=import-error, no-name-in-module from distutils.errors import DistutilsPlatformError -# pylint: disable=wrong-import-order # distutils is replaced by virtualenv with a module that does # weird path manipulations in order to get to the # real distutils module. -try: - import pkg_resources -except ImportError: - pkg_resources = None import six from .interpreter._import import spec @@ -384,7 +379,7 @@ def file_info_from_modpath(modpath, path=None, context_file=None): return _spec_from_modpath(modpath, path, context) elif modpath == ['os', 'path']: # FIXME: currently ignoring search_path... - return spec.ModuleSpec(name='os.path', location=os.path.__file__, type=imp.PY_SOURCE) + return spec.ModuleSpec(name='os.path', location=os.path.__file__, module_type=imp.PY_SOURCE) return _spec_from_modpath(modpath, path, context) @@ -595,7 +590,7 @@ def _spec_from_modpath(modpath, path=None, context=None): this function is used internally, see `file_from_modpath`'s documentation for more information """ - assert len(modpath) > 0 + assert modpath location = None if context is not None: try: @@ -609,7 +604,7 @@ def _spec_from_modpath(modpath, path=None, context=None): if found_spec.type == spec.ModuleType.PY_COMPILED: try: location = get_source_file(found_spec.location) - return found_spec._replace(location=location, type=spec.ModuleSpec.PY_SOURCE) + return found_spec._replace(location=location, type=spec.ModuleType.PY_SOURCE) except NoSourceFile: return found_spec._replace(location=location) elif found_spec.type == spec.ModuleType.C_BUILTIN: diff --git a/astroid/node_classes.py b/astroid/node_classes.py index 9f71ae5d..5c44b158 100644 --- a/astroid/node_classes.py +++ b/astroid/node_classes.py @@ -16,7 +16,6 @@ import warnings try: from functools import singledispatch as _singledispatch except ImportError: - # pylint: disable=import-error from singledispatch import singledispatch as _singledispatch import six @@ -540,7 +539,7 @@ class NodeNG(object): """Outputs a representation of a sequence that's contained within an AST.""" cur_indent += indent result.append('[') - if len(node) == 0: + if not node: broken = False elif len(node) == 1: broken = _repr_tree(node[0], result, done, cur_indent, depth) @@ -591,7 +590,7 @@ class NodeNG(object): fields.extend(node._astroid_fields) if ast_state: fields.extend(node._other_other_fields) - if len(fields) == 0: + if not fields: broken = False elif len(fields) == 1: result.append('%s=' % fields[0]) @@ -1348,23 +1347,23 @@ class Dict(NodeNG, bases.Instance): def itered(self): return self.items[::2] - def getitem(self, lookup_key, context=None): + def getitem(self, index, context=None): for key, value in self.items: # TODO(cpopa): no support for overriding yet, {1:2, **{1: 3}}. if isinstance(key, DictUnpack): try: - return value.getitem(lookup_key, context) + return value.getitem(index, context) except IndexError: continue for inferredkey in key.infer(context): if inferredkey is util.Uninferable: continue - if isinstance(inferredkey, Const) and isinstance(lookup_key, Const): - if inferredkey.value == lookup_key.value: + if isinstance(inferredkey, Const) and isinstance(index, Const): + if inferredkey.value == index.value: return value # This should raise KeyError, but all call sites only catch # IndexError. Let's leave it like that for now. - raise IndexError(lookup_key) + raise IndexError(index) def bool_value(self): return bool(self.items) @@ -1934,7 +1933,7 @@ class FormattedValue(NodeNG): class JoinedStr(NodeNG): """Represents a list of string expressions to be joined.""" _astroid_fields = ('values',) - value = None + values = None def postinit(self, values=None): self.values = values diff --git a/astroid/objects.py b/astroid/objects.py index cd3063e1..7a873449 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -56,6 +56,7 @@ class Super(node_classes.NodeNG): *self_class* is the class where the super call is, while *scope* is the function where the super call is. """ + # pylint: disable=unnecessary-lambda special_attributes = util.lazy_descriptor(lambda: objectmodel.SuperModel()) # pylint: disable=super-init-not-called @@ -182,6 +183,7 @@ class ExceptionInstance(bases.Instance): the case of .args. """ + # pylint: disable=unnecessary-lambda special_attributes = util.lazy_descriptor(lambda: objectmodel.ExceptionInstanceModel()) @@ -192,6 +194,7 @@ class DictInstance(bases.Instance): that methods such as .values or .items can be properly inferred. """ + # pylint: disable=unnecessary-lambda special_attributes = util.lazy_descriptor(lambda: objectmodel.DictModel()) diff --git a/astroid/protocols.py b/astroid/protocols.py index 15c620ed..93ec7a61 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -559,13 +559,13 @@ def starred_assigned_stmts(self, node=None, context=None, asspath=None): # anything before the starred node and from right to left # to remove anything after the starred node. - for index, node in enumerate(lhs.elts): - if not isinstance(node, nodes.Starred): + for index, left_node in enumerate(lhs.elts): + if not isinstance(left_node, nodes.Starred): elts.popleft() continue lhs_elts = collections.deque(reversed(lhs.elts[index:])) - for node in lhs_elts: - if not isinstance(node, nodes.Starred): + for right_node in lhs_elts: + if not isinstance(right_node, nodes.Starred): elts.pop() continue # We're done diff --git a/astroid/raw_building.py b/astroid/raw_building.py index 89a237de..8fa3e706 100644 --- a/astroid/raw_building.py +++ b/astroid/raw_building.py @@ -209,12 +209,12 @@ def _base_class_object_build(node, member, basenames, name=None, localname=None) except: # pylint: disable=bare-except pass else: - for name, obj in instdict.items(): + for item_name, obj in instdict.items(): valnode = nodes.EmptyNode() valnode.object = obj valnode.parent = klass valnode.lineno = 1 - klass.instance_attrs[name] = [valnode] + klass.instance_attrs[item_name] = [valnode] return klass @@ -374,6 +374,7 @@ def _astroid_bootstrapping(astroid_builtin=None): from six.moves import builtins astroid_builtin = Astroid_BUILDER.inspect_build(builtins) + # pylint: disable=redefined-outer-name for cls, node_cls in node_classes.CONST_CLS.items(): if cls is type(None): proxy = build_class('NoneType') diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py index 91774cfd..e898c16e 100644 --- a/astroid/rebuilder.py +++ b/astroid/rebuilder.py @@ -10,8 +10,8 @@ order to get a single Astroid representation """ -import _ast import sys +import _ast import astroid from astroid import astpeephole diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py index de99457c..a61e1d56 100644 --- a/astroid/scoped_nodes.py +++ b/astroid/scoped_nodes.py @@ -261,7 +261,6 @@ class Module(LocalsDictNodeNG): 'pure_python', 'future_imports') _other_other_fields = ('locals', 'globals') - # pylint: disable=redefined-builtin def __init__(self, name, doc, file=None, path=None, package=None, parent=None, pure_python=True): self.name = name @@ -628,6 +627,7 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG): # function's type, 'function' | 'method' | 'staticmethod' | 'classmethod' @property def type(self): + # pylint: disable=no-member if self.args.args and self.args.args[0].name == 'self': if isinstance(self.parent.scope(), ClassDef): return 'method' @@ -881,7 +881,6 @@ class FunctionDef(node_classes.Statement, Lambda): result = set() decoratornodes = [] if self.decorators is not None: - # pylint: disable=unsupported-binary-operation; damn flow control. decoratornodes += self.decorators.nodes decoratornodes += self.extra_decorators for decnode in decoratornodes: @@ -1680,7 +1679,6 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, if exc.args and exc.args[0] not in ('', None): return exc.args[0] return None - # pylint: disable=unsupported-binary-operation; false positive return [first] + list(slots) # Cached, because inferring them all the time is expensive diff --git a/astroid/tests/unittest_object_model.py b/astroid/tests/unittest_object_model.py index 742105d2..fbe88159 100644 --- a/astroid/tests/unittest_object_model.py +++ b/astroid/tests/unittest_object_model.py @@ -3,7 +3,6 @@ # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER import unittest -import types import xml import six @@ -103,6 +103,9 @@ disable=fixme,invalid-name, missing-docstring, too-few-public-methods, unused-argument,
# Not very useful when it warns about imports.
duplicate-code,
+ # Don't care about these two too much
+ wrong-import-order,
+ wrong-import-position
[BASIC]
@@ -3,6 +3,7 @@ envlist = py27, py33, py34, py35, py36, pypy, pylint skip_missing_interpreters = true [testenv:pylint] +basepython = python3.5 commands = pylint -rn --rcfile={toxinidir}/pylintrc {envsitepackagesdir}/astroid [testenv] |