簡體   English   中英

我們如何訪問 lint.run object 中的 pylint 消息?

[英]How can we access the pylint messages in lint.run object?

類似於我們通過以下方式使用 lint.run 訪問 pylint 分數的方式:

pylint_obj = lint.Run(args,reporter=reporter, do_exit=False) 
pylint_obj. linter.stats['global_note'] <- This is the score

是否有任何變量存儲像這樣的pylint消息:

status.py:348:4: W0612: Unused variable 'foo' (unused-variable)
status.py:373:4: W0612: Unused variable 'step_source_address' (unused-variable)
status.py:429:4: W0612: Unused variable 'range_status_destin' (unused-variable)
status.py:18:0: R0915: Too many statements (103/80) (too-many-statements)
status.py:524:0: R0913: Too many arguments (10/8) (too-many-arguments)
status.py:524:0: R0914: Too many local variables (34/15) (too-many-locals)

我需要訪問字符串消息並執行進一步的操作

pylint 本身有一個CollectingReporter pylint

from pylint import lint
from pylint.reporters import CollectingReporter


reporter = CollectingReporter()
pylint_obj = lint.Run([__file__], reporter=reporter, do_exit=False)
print(reporter.messages)

打印出來

[Message(msg_id='C0114', symbol='missing-module-docstring', msg='Missing module docstring', C='C', category='convention', confidence=Confidence(name='HIGH', description='No false positive possible.'), abspath='/Users/akx/build/so-misc/aa.py', path='aa.py', module='aa', obj='', line=1, column=0, end_line=None, end_column=None)]

(沒有別的,因為CollectingReporter本身不打印東西)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM