小编Rap*_*ipe的帖子

flake8 在 vscode 中没有显示致命错误

vscode 在 vscode 中没有显示致命错误。它只是突出显示代码中的警告。例子:

我有使用 python 2.7 从 virtualenv 运行 flake8 的 vscode。设置如下:

"python.linting.flake8Enabled": true,
Run Code Online (Sandbox Code Playgroud)

我正在将 vscode“问题”窗口的结果与直接从命令行运行 flake8 的结果进行比较。

"python.linting.flake8Enabled": true,
Run Code Online (Sandbox Code Playgroud)

当我从上面代码的命令行运行 flake8 时,我收到所有 linting 错误和警告,

> flake8 python/mock.py 
python/mock.py:4:5: F821 undefined name 'o'
python/mock.py:4:5: F841 local variable 'o' is assigned to but never used
python/mock.py:5:1: W293 blank line contains whitespace
Run Code Online (Sandbox Code Playgroud)

而当我在 vscode 中整理这段代码时,我只收到警告。

blank line contains whitespace flake8(W293) [5,1]
Run Code Online (Sandbox Code Playgroud)

我在配置中遗漏了什么吗?有没有办法检查 vscode 是如何调用 flake8 的?

python-2.7 flake8 visual-studio-code

6
推荐指数
1
解决办法
3265
查看次数

在 python 文档字符串中记录其他函数中可能发生的异常

在Python中,除了当前函数/方法体中引发的异常之外,我们是否应该在文档字符串中记录可以在其他函数/类中引发的异常?

观察:我正在考虑 Google Python 文档字符串风格https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

我已经很长时间没有使用 Java 了,但在那里你会明确地说你的方法可以使用“throws”关键字引发什么样的异常。

例如。:

class MyException(Exception):
    pass

class A(object):
    def foo(self):
       """This class does foo

       Returns:
           Int: The number of foo.

       Raises:
            MyException - In case something happen
       """
       if True:
           raise MyException
       return 0

class B(object):
    def __init__(self):
        self._a = A()

    def bar(self):
        """This class does bar
        Returns:
            Int: number of bar
        Raises:
             MyException ????? Should this be here?
        """

        return self._a.foo()
Run Code Online (Sandbox Code Playgroud)

python documentation docstring exception

5
推荐指数
1
解决办法
4120
查看次数