Given the following python code:
import git
try:
raise git.exc.GitCommandError("dummy", "foo")
except git.exc.GitCommandError as exc:
print(exc)
pylint complains
************* 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)
The code works fine, I do not understand the errors. git.exc is not an exception, but a module:
> 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 version is 2.3.1. I'm wondering whether this is just a bug in pylint or whether I'm missing something...
Update: Using git.GitCommandError instead of git.exc.GitCommandError doesn't produce the same error for some reason. Even though the latter is the original name of the class.
答案 0 :(得分:0)
这是由于git.exc.*
子软件包暴露在顶级git.*
软件包中。参见git/__init__.py
,尤其是第38行,我们可以找到以下内容:
from git.exc import *