python-3.xattributeerrorpylintpylintrcastroid

pylint and astroid AttributeError: 'Module' object has no attribute 'col_offset'


It fails using pylint version 2.9.0 and 2.9.3. With version 2.8.3 it still works though.

See GitHub-issue under the provided link.

Traceback (most recent call last):

  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/inference_tip.py", line 19, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x7f310b222700>, <Call l.166 at 0x7f3102ebf970>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.pyenv/versions/3.8.8/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 973, in check
    self._check_files(
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1007, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1170, in check_astroid_module
    retval = self._check_astroid_module(
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1215, in _check_astroid_module
    walker.walk(ast_node)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/checkers/typecheck.py", line 1071, in visit_assign
    self._check_assignment_from_function_call(node)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/checkers/typecheck.py", line 1081, in _check_assignment_from_function_call
    function_node = safe_infer(node.value.func)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/pylint/checkers/utils.py", line 1177, in safe_infer
    value = next(infer_gen)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/node_classes.py", line 353, in infer
    yield from self._infer(context, **kwargs)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/inference.py", line 299, in infer_attribute
    for owner in self.expr.infer(context):
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/node_classes.py", line 367, in infer
    for i, result in enumerate(generator):
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/bases.py", line 144, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/node_classes.py", line 367, in infer
    for i, result in enumerate(generator):
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/bases.py", line 144, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/node_classes.py", line 343, in infer
    results = tuple(self._explicit_inference(self, context, **kwargs))
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/inference_tip.py", line 21, in _inference_tip_cached
    result = func(*args, **kwargs)
  File "/root/.pyenv/versions/3.8.8/lib/python3.8/site-packages/astroid/brain/brain_builtin_inference.py", line 203, in _transform_wrapper
    if result.col_offset is None:
AttributeError: 'Module' object has no attribute 'col_offset'

The requirements.txt - file of this testing environment contains:

astroid
src/packages/project/requirements.txt
pycodestyle
pylint
pylint_junit
pytest
pytest-cov
yapf

with src/packages/project/requirements.txt containing:

awswrangler==2.8.0
babel==2.9.1
boto3==1.17.77
botocore==1.20.77
category-encoders==2.2.2
joblib==1.0.1
markdown==3.3.4
matplotlib==3.3.4
openpyxl==3.0.7
pandas==1.1.5
pyarrow==4.0.0
pytz==2021.1
requests==2.25.1
scikit-learn==0.24.2
simple_salesforce==1.0.0

EDIT on different attempts producing the same error:

  1. Installing pylint=2.9.3
  2. Installing astroid and pylint (latest versions, no version specification)
  3. Installing astroid and pylint and upgrade astroid to latest version during build-process (in AWS test-buildspec.yml) via pip install --upgrade astroid (suggested here)

Solution

  • Thanks to the work of @Pierre.Sassoulas this issue has been resolved (see here).

    After having proven that the following combination of pylint - and astroid - versions worked well together without producing the OP-error, new commits have been made to the GitHub-project to fix the problem:

    pip install pylint==2.9.3
    pip install git+git://github.com/PyCQA/astroid.git@c37b6fd47b62486fd6cbe77b913b568b809f1a6d#egg=astroid
    

    From here going forward, the issue should not occur again installing the latest version of pylint combined with astroid. Yet, if the issue returns, I'll let you know here.