pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.31k stars 1.13k forks source link

Pylint 2.2.2 crashes with DuplicateBasesError #2754

Closed cglacet closed 4 years ago

cglacet commented 5 years ago

When I run pylint on one of my (large) file, it crashes on the last line. The last thing that is printed as a pylint error is:

main.py:1984:0: C0103: Constant name "my_web_app" doesn't conform to 
UPPER_CASE naming style (invalid-name)
The complete stack trace is: ``` Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 168, in getattr values = self._proxied.instance_attr(name, context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2270, in instance_attr context=context) astroid.exceptions.AttributeInferenceError: 'router' not found on . The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 204, in igetattr get_attr = self.getattr(name, context, lookupclass=False) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 183, in getattr ) from exc astroid.exceptions.AttributeInferenceError: 'router' not found on . During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 31, in cached return cache[func] KeyError: > During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/bin/pylint", line 10, in sys.exit(run_pylint()) File "/usr/local/lib/python3.7/site-packages/pylint/__init__.py", line 20, in run_pylint Run(sys.argv[1:]) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1608, in __init__ linter.check(args) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 938, in check self._do_check(files_or_modules) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1071, in _do_check self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1154, in check_astroid_module walker.walk(ast_node) File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk self.walk(child) File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk self.walk(child) File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1266, in walk cb(astroid) File "/usr/local/lib/python3.7/site-packages/pylint/checkers/logging.py", line 215, in visit_call result, name = is_logger_class() File "/usr/local/lib/python3.7/site-packages/pylint/checkers/logging.py", line 197, in is_logger_class for inferred in node.func.infer(): File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 293, in infer_attribute for owner in self.expr.infer(context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 314, in infer_attribute yield from owner.igetattr(self.attrname, context) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 214, in igetattr yield from self._wrap_attr(attrs, context) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 223, in _wrap_attr yield from attr.infer_call_result(self, context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 1628, in infer_call_result yield from returnnode.value.infer(context) File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 314, in infer_attribute yield from owner.igetattr(self.attrname, context) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 205, in igetattr yield from _infer_stmts(self._wrap_attr(get_attr, context), context, frame=self) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 211, in infer_call for callee in self.func.infer(context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 89, in wrapped generator = _func(node, context, **kwargs) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 268, in infer_import_from module = self.do_import_module() File "/usr/local/lib/python3.7/site-packages/astroid/mixins.py", line 101, in do_import_module relative_only=level and level >= 1) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 602, in import_module return MANAGER.ast_from_module_name(absmodname) File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 150, in ast_from_module_name return self.ast_from_file(found_spec.location, modname, fallback=False) File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 83, in ast_from_file return AstroidBuilder(self).file_build(filepath, modname) File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 128, in file_build return self._post_build(module, encoding) File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 148, in _post_build self.delayed_assattr(delayed) File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 214, in delayed_assattr if not _can_assign_attr(inferred, node.attrname): File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 57, in _can_assign_attr slots = node.slots() File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 33, in cached cache[func] = result = func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2656, in slots slots = list(grouped_slots()) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2642, in grouped_slots for cls in self.mro()[:-1]: File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2735, in mro return self._compute_mro(context=context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2716, in _compute_mro _verify_duplicates_mro(unmerged_mro, self, context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 94, in _verify_duplicates_mro mros=sequences, cls=cls, context=context) astroid.exceptions.DuplicateBasesError: Duplicates found in MROs (AbstractResource), (_GenericAlias, _Final, object), (_GenericAlias, _Final, object), (_GenericAlias, _GenericAlias) for . ```
PCManticore commented 5 years ago

Is it possible to find a minimal reproduction example?

cglacet commented 5 years ago

I'm actually very surprised but yes! Here is the minimal 3-line file I could reproduce the bug with:

main.py

from aiohttp import web

my_web_app = web.Application()
my_web_app.router.add_get('/trip', index)
The complete output from `pylint main.py` ```bash ************* Module main main.py:1:0: C0111: Missing module docstring (missing-docstring) main.py:3:0: C0103: Constant name "my_web_app" doesn't conform to UPPER_CASE naming style (invalid-name) Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 168, in getattr values = self._proxied.instance_attr(name, context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2270, in instance_attr context=context) astroid.exceptions.AttributeInferenceError: 'router' not found on . The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 204, in igetattr get_attr = self.getattr(name, context, lookupclass=False) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 183, in getattr ) from exc astroid.exceptions.AttributeInferenceError: 'router' not found on . During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 31, in cached return cache[func] KeyError: > During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/bin/pylint", line 10, in sys.exit(run_pylint()) File "/usr/local/lib/python3.7/site-packages/pylint/__init__.py", line 20, in run_pylint Run(sys.argv[1:]) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1608, in __init__ linter.check(args) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 938, in check self._do_check(files_or_modules) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1071, in _do_check self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers) File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1154, in check_astroid_module walker.walk(ast_node) File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk self.walk(child) File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk self.walk(child) File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1266, in walk cb(astroid) File "/usr/local/lib/python3.7/site-packages/pylint/checkers/logging.py", line 215, in visit_call result, name = is_logger_class() File "/usr/local/lib/python3.7/site-packages/pylint/checkers/logging.py", line 197, in is_logger_class for inferred in node.func.infer(): File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 293, in infer_attribute for owner in self.expr.infer(context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 314, in infer_attribute yield from owner.igetattr(self.attrname, context) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 214, in igetattr yield from self._wrap_attr(attrs, context) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 223, in _wrap_attr yield from attr.infer_call_result(self, context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 1628, in infer_call_result yield from returnnode.value.infer(context) File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 314, in infer_attribute yield from owner.igetattr(self.attrname, context) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 205, in igetattr yield from _infer_stmts(self._wrap_attr(get_attr, context), context, frame=self) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 211, in infer_call for callee in self.func.infer(context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped res = next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts for inferred in stmt.infer(context=context): File "/usr/local/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference yield from islice(iterator, size) File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator for result in generator: File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred yield next(generator) File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 89, in wrapped generator = _func(node, context, **kwargs) File "/usr/local/lib/python3.7/site-packages/astroid/inference.py", line 268, in infer_import_from module = self.do_import_module() File "/usr/local/lib/python3.7/site-packages/astroid/mixins.py", line 101, in do_import_module relative_only=level and level >= 1) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 602, in import_module return MANAGER.ast_from_module_name(absmodname) File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 150, in ast_from_module_name return self.ast_from_file(found_spec.location, modname, fallback=False) File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 83, in ast_from_file return AstroidBuilder(self).file_build(filepath, modname) File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 128, in file_build return self._post_build(module, encoding) File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 148, in _post_build self.delayed_assattr(delayed) File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 214, in delayed_assattr if not _can_assign_attr(inferred, node.attrname): File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 57, in _can_assign_attr slots = node.slots() File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 33, in cached cache[func] = result = func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2656, in slots slots = list(grouped_slots()) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2642, in grouped_slots for cls in self.mro()[:-1]: File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2735, in mro return self._compute_mro(context=context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2716, in _compute_mro _verify_duplicates_mro(unmerged_mro, self, context) File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 94, in _verify_duplicates_mro mros=sequences, cls=cls, context=context) astroid.exceptions.DuplicateBasesError: Duplicates found in MROs (AbstractResource), (_GenericAlias, _Final, object), (_GenericAlias, _Final, object), (_GenericAlias, _GenericAlias) for . ```
brycepg commented 5 years ago

Thanks, I can reproduce with:

pylint 2.3.0-dev1
astroid 2.1.0
Python 3.7.2 (default, Jan 16 2019, 19:49:22) 

and

aiohttp==3.5.4


I cut down the code with the error (aiohttp/web_urldispatcher.py) until I couldn't remove any more code. Here's my minimum working example without aiohttp:

from typing import (                                                                         
    Iterable,                                                                                
    Sized,                                                                                   
)                                                                                            

class AbstractResource(Sized, Iterable):                                                     
    def __init__(self):                                                                      
        self.bar = 1 # Probably triggers inference                                           
SamyCookie commented 5 years ago

Is https://github.com/PyCQA/pylint/commit/e3d4e80ca9be6b61d7c9773f8a20661a52fa9ed9 and https://github.com/PyCQA/astroid/pull/634 close this issue ?

brycepg commented 4 years ago

@SamyCookie yeah this is no longer an issue on master, thanks