[英]Linting error on BitBucket: TypeError: 'LinterStats' object is not subscriptable
我正在使用 BitBucket 管道使用 pylint 執行 linting 檢查。 幾個小時前它工作正常。 即使最終分數遠遠超過最低標准(8.0),我也一直面臨以下錯誤:
您的代碼已被評為 9.43/10
Traceback (most recent call last):
File "/usr/local/bin/pylint-fail-under", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.6/dist-packages/pylint_fail_under/__main__.py", line 42, in main
score = results.linter.stats["global_note"]
TypeError: 'LinterStats' object is not subscriptable
不要使用pylint-fail-under
, pylint 自 pylint 2.5.0
以來有一個失敗選項,並且它的維護者不會為更新的 pylint 更新此 package。
pylint-fail-under --fail_under 8.0
更改為pylint --fail-under=8.0
並刪除對pylint-fail-under
的依賴。
另見https://github.com/PyCQA/pylint/issues/5405和: https://github.com/TNThieding/pylint-fail-under/issues/8#issuecomment-62636956
另一種選擇是降級,如果不妨礙:pylint==2.11.1
TypeError: 'LinterStats' object is not subscriptable
只是意味着, LinterStats
不可識別(請參閱: 如果 Python object 是否“可下標”,這意味着什么? )
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Print ``pylint`` score (old way)."""
from pylint.lint import Run
score = Run([...], exit=False).linter.stats["global_note"]
print(score)
示例: https://github.com/apmechev/pylint-badge/blob/master/pylintbadge/pylintbadge.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Print ``pylint`` score (new way)."""
from pylint.lint import Run
score = Run([...], exit=False).linter.stats.global_note
print(score)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Print ``pylint`` score (new & silent way)."""
import sys
from typing import TextIO
from pylint.lint import Run
default_stdout = sys.stdout
sys.stdout = type("Dummy", (TextIO,), {"write": lambda self, data: ()})()
score = Run(["./src"], exit=False).linter.stats.global_note
sys.stdout = default_stdout
print(score)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.