gpt4 book ai didi

pylint - pylint 和 git.exc 的奇怪错误

转载 作者:行者123 更新时间:2023-12-05 04:01:34 37 4
gpt4 key购买 nike

给定以下 python 代码:

import git

try:
raise git.exc.GitCommandError("dummy", "foo")
except git.exc.GitCommandError as exc:
print(exc)

pylint 提示

************* 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 不是一个异常(exception),而是一个模块:

> 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

关于pylint - pylint 和 git.exc 的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55244396/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com