Closed adarob closed 2 years ago
Thanks! I'm trying to reproduce it using your branch, do you have a particular invocation of pylint
you used?
I've widdled it down to this one: pylint magenta.models.latent_transfer.train_joint
Hello @PCManticore,
We've run into a similar issue, but with a different error when running pylint on aiohttp
( https://github.com/aio-libs/aiohttp )
It detect that the class AbstractResource (https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_urldispatcher.py#L55) inherit from the same base class which is imho wrong.
Here is the traceback:
File "/home/benoit/Projects/src/astroid/astroid/decorators.py", line 31, in cached
return cache[func]
KeyError: <bound method ClassDef.slots of <ClassDef.AbstractResource l.55 at 0x7f75b1653518>>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/benoit/Projects/src/pylint/pylint/lint.py", line 1131, in get_ast
return MANAGER.ast_from_file(filepath, modname, source=True)
File "/home/benoit/Projects/src/astroid/astroid/manager.py", line 87, in ast_from_file
return AstroidBuilder(self).file_build(filepath, modname)
File "/home/benoit/Projects/src/astroid/astroid/builder.py", line 136, in file_build
return self._post_build(module, encoding)
File "/home/benoit/Projects/src/astroid/astroid/builder.py", line 156, in _post_build
self.delayed_assattr(delayed)
File "/home/benoit/Projects/src/astroid/astroid/builder.py", line 230, in delayed_assattr
if not _can_assign_attr(inferred, node.attrname):
File "/home/benoit/Projects/src/astroid/astroid/builder.py", line 57, in _can_assign_attr
slots = node.slots()
File "/home/benoit/Projects/src/astroid/astroid/decorators.py", line 33, in cached
cache[func] = result = func(*args, **kwargs)
File "/home/benoit/Projects/src/astroid/astroid/scoped_nodes.py", line 2703, in slots
slots = list(grouped_slots())
File "/home/benoit/Projects/src/astroid/astroid/scoped_nodes.py", line 2688, in grouped_slots
for cls in self.mro()[:-1]:
File "/home/benoit/Projects/src/astroid/astroid/scoped_nodes.py", line 2785, in mro
return self._compute_mro(context=context)
File "/home/benoit/Projects/src/astroid/astroid/scoped_nodes.py", line 2765, in _compute_mro
_verify_duplicates_mro(unmerged_mro, self, context)
File "/home/benoit/Projects/src/astroid/astroid/scoped_nodes.py", line 99, in _verify_duplicates_mro
context=context,
astroid.exceptions.DuplicateBasesError: Duplicates found in MROs (AbstractResource), (_GenericAlias, _Final, object), (_GenericAlias, _Final, object), (_GenericAlias, _GenericAlias) for <ClassDef.AbstractResource l.55 at 0x7f75b1653518>.```
@dzen Please open a separate issue, that seems unrelated to the problem reported in this one. Thanks!
@adarob Here is a tiny reproducing example.
def f():
if False:
def g(x):
pass
def h():
fa = partial(g, x=0)
fb = partial(g, x=0)
astroid.exceptions.AstroidError: Could not find <PartialFunction.g l.3 at 0x7f909da9ffd0> in <If l.2 at 0x7f909da9fa20>'s children
It looks there is a problem in locate_child
comparing function g
with a partial application in h
:
(Pdb) child
<PartialFunction.g l.3 at 0x7f0255d5b080>
(Pdb) self.body
[<FunctionDef.g l.3 at 0x7f025605dac8>, <FunctionDef.h l.6 at 0x7f025605db38>]
Thanks for the investigation @nickdrozd this might be caused by the fact that PartialFunction
is a dynamic construct, being constructed at inference time https://github.com/PyCQA/astroid/blob/cab26ec5c0f300855462ff79e93b107064983f44/astroid/brain/brain_functools.py#L102 I'm not sure where the bug is, but locate_child
should probably be aware of dynamic objects such as this.
I'm seeing this similar error (v2.1.0):
Traceback (most recent call last):
File "/home/brannon/Workspace/lbry/lbry-venv/bin/pylint", line 10, in <module>
sys.exit(run_pylint())
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/__init__.py", line 20, in run_pylint
Run(sys.argv[1:])
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 1608, in __init__
linter.check(args)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 938, in check
self._do_check(files_or_modules)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 1071, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 1154, in check_astroid_module
walker.walk(ast_node)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk
self.walk(child)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk
self.walk(child)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk
self.walk(child)
[Previous line repeated 1 more time]
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1266, in walk
cb(astroid)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/checkers/typecheck.py", line 1055, in visit_call
called, implicit_args, callable_name = _determine_callable(called)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/checkers/typecheck.py", line 461, in _determine_callable
new = callable_obj.local_attr("__new__")[-1]
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2279, in local_attr
class_node = next(self.local_attr_ancestors(name, context), None)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2230, in local_attr_ancestors
ancestors = self.mro(context)[1:]
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2779, in mro
raise NotImplementedError("Could not obtain mro for old-style classes.")
NotImplementedError: Could not obtain mro for old-style classes.
Here's another one (with v2.0.1):
Traceback (most recent call last):
File "/home/brannon/Workspace/lbry/lbry-venv/bin/pylint", line 10, in <module>
sys.exit(run_pylint())
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/__init__.py", line 20, in run_pylint
Run(sys.argv[1:])
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 1608, in __init__
linter.check(args)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 938, in check
self._do_check(files_or_modules)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 1071, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/lint.py", line 1154, in check_astroid_module
walker.walk(ast_node)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk
self.walk(child)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk
self.walk(child)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1269, in walk
self.walk(child)
[Previous line repeated 1 more time]
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/utils.py", line 1266, in walk
cb(astroid)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/checkers/typecheck.py", line 1035, in visit_call
called = safe_infer(node.func)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/pylint/checkers/utils.py", line 1077, in safe_infer
next(inferit)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
yield next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/inference.py", line 288, in infer_attribute
for owner in self.expr.infer(context):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
yield next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/inference.py", line 309, in infer_attribute
yield from owner.igetattr(self.attrname, context)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 211, in igetattr
yield from self._wrap_attr(attrs, context)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 220, in _wrap_attr
yield from attr.infer_call_result(self, context)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 1628, in infer_call_result
yield from returnnode.value.infer(context)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
yield next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/inference.py", line 309, in infer_attribute
yield from owner.igetattr(self.attrname, context)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 202, in igetattr
yield from _infer_stmts(self._wrap_attr(get_attr, context), context, frame=self)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
for inferred in stmt.infer(context=context):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
for inferred in stmt.infer(context=context):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
for inferred in stmt.infer(context=context):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
for inferred in stmt.infer(context=context):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
yield next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/inference.py", line 205, in infer_call
for callee in self.func.infer(context):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
res = next(generator)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
for inferred in stmt.infer(context=context):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
yield from islice(iterator, size)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
for result in generator:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 89, in wrapped
generator = _func(node, context, **kwargs)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/inference.py", line 263, in infer_import_from
module = self.do_import_module()
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/mixins.py", line 101, in do_import_module
relative_only=level and level >= 1)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 602, in import_module
return MANAGER.ast_from_module_name(absmodname)
File "/home/brannon/Workspace/lbry/lbry-venv/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 "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/manager.py", line 83, in ast_from_file
return AstroidBuilder(self).file_build(filepath, modname)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/builder.py", line 128, in file_build
return self._post_build(module, encoding)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/builder.py", line 148, in _post_build
self.delayed_assattr(delayed)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/builder.py", line 214, in delayed_assattr
if not _can_assign_attr(inferred, node.attrname):
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/builder.py", line 57, in _can_assign_attr
slots = node.slots()
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/decorators.py", line 33, in cached
cache[func] = result = func(*args, **kwargs)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2653, in slots
slots = list(grouped_slots())
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2639, in grouped_slots
for cls in self.mro()[:-1]:
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2732, in mro
return self._compute_mro(context=context)
File "/home/brannon/Workspace/lbry/lbry-venv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 2713, in _compute_mro
_verify_duplicates_mro(unmerged_mro, self, context)
File "/home/brannon/Workspace/lbry/lbry-venv/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 <ClassDef.AbstractResource l.75 at 0x7f488a4cb6a0>.
@nickdrozd This https://github.com/PyCQA/astroid/issues/627#issuecomment-453196243 crashed with pylint
right? I'm no longer seeing a crash with current main
of pylint
and astroid
.
@adarob, @dzen or @BrannonKing If any of you is still interested in this issue. Could you try and see if this has been resolved in the latest versions?
Yeah that snippet used to crash, but now it doesn't. I don't know about the original issue though. It seems like something got fixed at least.
The DuplicateBasesError
for _GenericAlias
was fixed a while ago. If the other issue can't be reproduced anymore too, let's close it. If someone still has an issue with it, please leave a comment and this can be reopened.
Steps to reproduce
https://github.com/tensorflow/magenta/pull/1374
python setup.py install
pylint magenta
.Current behavior
Expected behavior
Should not crash
python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
output1.6.1