pylint - pylint 和 git.exc 的奇怪错误
问题描述
给定以下python代码:
import git
try:
raise git.exc.GitCommandError("dummy", "foo")
except git.exc.GitCommandError as exc:
print(exc)
皮林特抱怨
************* Module test
[...irrelevant errors removed...]
test.py:4:7: E1101: Instance of 'GitError' has no 'GitCommandError' member (no-member)
test.py:4:7: E1101: Instance of 'Exception' has no 'GitCommandError' member (no-member)
test.py:5:7: E1101: Instance of 'Exception' has no 'GitCommandError' member (no-member)
test.py:5:7: E1101: Instance of 'GitError' has no 'GitCommandError' member (no-member)
---------------------------------------------------------------------
Your code has been rated at -36.00/10 (previous run: 4.00/10, -40.00)
代码工作正常,我不明白错误。git.exc 不是一个例外,而是一个模块:
> python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> git.exc
<module 'git.exc' from '/tmp/tmp.ULCyvtUQWx/testenv/lib/python3.5/site-packages/GitPython-2.1.11-py3.5.egg/git/exc.py'>
pylint 版本是 2.3.1。我想知道这是否只是 pylint 中的一个错误,或者我是否遗漏了一些东西......
更新:由于某种原因,使用 git.GitCommandError 代替 git.exc.GitCommandError 不会产生相同的错误。尽管后者是该类的原始名称。
解决方案
尝试:from git.exc import GitCommandError
而不仅仅是import git
.
推荐阅读
- sql - bigquery 使用正则表达式连接表
- angular - 在 Angular 组件的其余部分之前完全加载订阅
- c# - 如何使用 Mutex 解决可能的竞争条件
- python - 为什么 win32api.SendMessage 不能在某些应用程序中执行鼠标点击
- php - 如何将 argv 与 file_get_contents 或 cURL 或类似的东西一起使用
- google-cloud-platform - Google Vision OCR,将文字坐标从 90、180、270 个文档旋转到 0 度
- javascript - 对象分配以更新对象的嵌套对象
- python - 我如何将一列值转换为个性化的列标题
- ios - React Native - iOS 模拟器部署目标“IPHONEOS_DEPLOYMENT_TARGET”设置为 7.0
- java - 如何通过以下方法修复 Stackoverflow?