首页 > 解决方案 > 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 不会产生相同的错误。尽管后者是该类的原始名称。

标签: pylintgitpython

解决方案


尝试:from git.exc import GitCommandError而不仅仅是import git.


推荐阅读