pylint 和 astroid AttributeError: 'Module' 对象没有属性 'col_offset'

如何解决pylint 和 astroid AttributeError: 'Module' 对象没有属性 'col_offset'

使用 pylint 版本 2.9.02.9.3 时失败。使用版本 2.8.3 它仍然有效。

请参阅所提供链接下的 GitHub-issue

回溯(最近一次调用最后一次):

  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 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",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'

requirements.txt - 此测试环境的文件包含:

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

src/packages/project/requirements.txt 包含:

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

对产生相同错误的不同尝试进行编辑:

  1. 安装pylint=2.9.3
  2. 安装 astroidpylint(最新版本,无版本规范)
  3. 在构建过程中(在 AWS test-buildspec.yml 中)通过 astroid 安装 pylintastroid 并将 pip install --upgrade astroid 升级到最新版本(建议 {{3} })

解决方法

您似乎在 pylint 2.9 中发现了错误/崩溃,您可以打开问题 here。您可以在修复期间降级到 2.8.3。

,

感谢@Pierre.Sassoulas 的工作,此问题已得到解决(请参阅 here)。

在证明 pylint - 和 astroid - 版本的以下组合可以很好地协同工作而不会产生 OP 错误后,对 GitHub-project 进行了新的提交以修复问题:

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

从这里开始,安装最新版本的 pylint 和 astroid 应该不会再次出现问题。但是,如果问题再次出现,我会在此处通知您。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?