landscapeio / prospector

Inspects Python source files and provides information about type and location of classes, methods etc
GNU General Public License v2.0
1.94k stars 171 forks source link

Tool pylint failed to run because of django.db.models.DecimalField #326

Open aldokkani opened 5 years ago

aldokkani commented 5 years ago

This happened out of a sudden, I didn't change anything.

Output:

Messages
========

.
  Line: None
    pylint: failure / Tool pylint failed to run (exception was raised)

Traceback:

Traceback (most recent call last):
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/__init__.py", line 89, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function apply_type_shim at 0x7f6cd3304e18>, <ClassDef.DecimalField l.1443 at 0x7f6cd0b6bb00>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/manager.py", line 129, in ast_from_module_name
    module = modutils.load_module_from_name(modname)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/modutils.py", line 196, in load_module_from_name
    return load_module_from_modpath(dotted_name.split('.'), path, use_sys)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/modutils.py", line 239, in load_module_from_modpath
    module = imp.load_module(curname, mp_file, mp_filename, mp_desc)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/imp.py", line 342, in load_dynamic
    return _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: libmpdec.so.2: cannot open shared object file: No such file or directory

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/hossam/.virtualenvs/hayya/bin/prospector", line 10, in <module>
    sys.exit(main())
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/prospector/run.py", line 173, in main
    prospector.execute()
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/prospector/run.py", line 66, in execute
    messages += tool.run(found_files)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/prospector/tools/pylint/__init__.py", line 256, in run
    self._linter.check(self._args)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/lint.py", line 801, in check
    self._do_check(files_or_modules)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/lint.py", line 938, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/lint.py", line 1018, in check_astroid_module
    walker.walk(ast_node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/utils.py", line 1162, in walk
    self.walk(child)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/utils.py", line 1159, in walk
    cb(astroid)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/checkers/classes.py", line 644, in visit_classdef
    self._check_bases_classes(node)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/checkers/classes.py", line 1272, in _check_bases_classes
    unimplemented_abstract_methods(node, is_abstract).items(),
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/checkers/utils.py", line 569, in unimplemented_abstract_methods
    infered = safe_infer(obj)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint/checkers/utils.py", line 828, in safe_infer
    value = next(inferit)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/inference.py", line 211, in infer_call
    for callee in self.func.infer(context):
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/inference.py", line 314, in infer_attribute
    yield from owner.igetattr(self.attrname, context)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/node_classes.py", line 325, in infer
    return self._explicit_inference(self, context, **kwargs)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/__init__.py", line 91, in _inference_tip_cached
    result = func(*args, **kwargs)
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/pylint_django/transforms/fields.py", line 44, in apply_type_shim
    base_nodes = MANAGER.ast_from_module_name('_decimal').lookup('Decimal')
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/manager.py", line 157, in ast_from_module_name
    raise e
  File "/home/hossam/.virtualenvs/hayya/lib/python3.7/site-packages/astroid/manager.py", line 133, in ast_from_module_name
    modname=modname, path=found_spec.location) from ex
astroid.exceptions.AstroidImportError: <exception str() failed>

requirements:

astroid==2.0.4
dodgy==0.1.9
isort==4.3.15
lazy-object-proxy==1.3.1
mccabe==0.6.1
pep8-naming==0.4.1
prospector==1.1.6.2
pycodestyle==2.4.0
pydocstyle==3.0.0
pyflakes==1.6.0
pylint==2.1.1
pylint-celery==0.3
pylint-django==2.0.2
pylint-flask==0.5
pylint-plugin-utils==0.5
PyYAML==5.1
requirements-detector==0.6
setoptconf==0.2.0
six==1.12.0
snapshottest==0.5.0
snowballstemmer==1.2.1
termcolor==1.1.0
wrapt==1.11.1
aldokkani commented 5 years ago

This happens because of Django django.db.models.DecimalField

danihodovic commented 5 years ago

I'm seeing the same issue with pylint v2.3.1.

from wagtail.core.models import Page

class BlogIndexPage(Page):
    content_panels = Page.content_panels  # noqa
$ pylint --version
pylint 2.3.1
astroid 2.2.5
Python 3.7.3 (default, Apr  9 2019, 04:56:51)
[GCC 8.3.0]
$ pylint blog/models2.py

Traceback (most recent call last):
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/__init__.py", line 91, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function infer_key_classes at 0x7f37c6971378>, <Call l.245 at 0x7f37c5dbd550>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dani/repos/jobs_aggregator/venv/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/__init__.py", line 20, in run_pylint
    Run(sys.argv[1:])
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/lint.py", line 1628, in __init__
    linter.check(args)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/lint.py", line 943, in check
    self._do_check(files_or_modules)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/lint.py", line 1075, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/lint.py", line 1158, in check_astroid_module
    walker.walk(ast_node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/utils.py", line 1303, in walk
    self.walk(child)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/utils.py", line 1300, in walk
    cb(astroid)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 57, in augment_func
    augmentation(chain, node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 148, in do_suppress
    chain()
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_plugin_utils/__init__.py", line 56, in chain
    old_method(node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/checkers/classes.py", line 729, in visit_classdef
    self._check_bases_classes(node)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/checkers/classes.py", line 1444, in _check_bases_classes
    unimplemented_abstract_methods(node, is_abstract).items(),
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/checkers/utils.py", line 782, in unimplemented_abstract_methods
    infered = safe_infer(obj)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint/checkers/utils.py", line 1066, in safe_infer
    value = next(inferit)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/bases.py", line 137, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/node_classes.py", line 348, in infer
    return self._explicit_inference(self, context, **kwargs)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/__init__.py", line 93, in _inference_tip_cached
    result = func(*args, **kwargs)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/pylint_django/transforms/foreignkey.py", line 96, in infer_key_classes
    MANAGER.ast_from_module_name(module_name)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/manager.py", line 178, in ast_from_module_name
    raise e
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/manager.py", line 129, in ast_from_module_name
    found_spec = self.file_from_module_name(modname, context_file)
  File "/home/dani/repos/jobs_aggregator/venv/lib/python3.7/site-packages/astroid/manager.py", line 222, in file_from_module_name
    raise value
astroid.exceptions.AstroidImportError: Failed to import module contenttypes.models with error:
No module named contenttypes.models.
djstein commented 4 years ago

still experiencing this with a content type... error occurs when I add a init.py file

error

astroid.exceptions.AstroidImportError: Failed to import module <app>.models with error:
No module named <app>.models.

folder structure

project/
    app/
        __init__.py
        models.py <- where it says offending content type error occurs
    __init__.py <- when added, get error. deletion lints files normally
Jasper-Koops commented 3 years ago

Just ran into a similar issue when using string literals in a Django ForeignKey:

    product = models.ForeignKey(
        "curriculum.Product",
    )

Which caused prospector to raise the following error:

astroid.exceptions.AstroidImportError: Failed to import module curriculum.models with error:
   No module named curriculum.models.

After reading your comment I found a __init__.py file residing in my src directory and the issue disappeared when I removed this file!

project/
      src/
          users/
          curriculum
          (...)
           __init__.py

So, future perusers of this thread, delete your redundant __init__.py files, it might solve the issue!