Tob*_*ann 5 python pylint python-3.x
到下面的代码:
"""Test with unused return value"""
from typing import List
def sorted_int_list(values: List[int]) -> List[int]:
"""Returns a new, sorted list"""
return sorted(values)
def main() -> None:
"""Ignoring value returned by sorted_int_list"""
values: List[int] = [3, 1, 2]
sorted_int_list(values) # Should create some kind or error
print(values)
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
pylint说:
Your code has been rated at 10.00/10
Run Code Online (Sandbox Code Playgroud)
但是我想让它报告未使用的返回值sorted_int_list。能做到吗?
小智 1
Python是动态语言,静态分析工具无法知道函数是否有返回值。例如:
def foo(a):
if a>0 return 42
else: pass #do nothing, and not return if a <= 0
Run Code Online (Sandbox Code Playgroud)
静态分析工具无法帮助你解决逻辑问题。
相关讨论: https: //github.com/PyCQA/pylint/issues/647
| 归档时间: |
|
| 查看次数: |
699 次 |
| 最近记录: |