python - python中的编译指示

标签 python pragma

我正在阅读 bottle.py 源代码。它是一个 Web 框架,只有 3000 多行 Python 代码。太酷了。

我发现了一些这样的代码:

class ServerAdapter(object):
    quiet = False
    def __init__(self, host='127.0.0.1', port=8080, **config):
        self.options = config
        self.host = host
        self.port = int(port)

    def run(self, handler): # pragma: no cover
        pass
    ... 

# pragma: no cover 是什么意思?我在 python 文档中找不到任何关于 pragma 语法的介绍。

最佳答案

显然与 coverage.py 有关:

Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.

确切的 # pragma: no cover 提示该工具应忽略该部分代码 -- 参见 Excluding code from coverage .

关于python - python中的编译指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11992448/

相关文章:

python - 何时以及如何创建 sqlalchemy 链接表对象?

c++ - 即使我一次使用编译指示,也会出现C++错误C2535

c - 程序执行是否总是从 C 中的 main 开始?

c++ - 编译优化与编译目标的区别是什么

python通过http将正则表达式传递给mongo

python - 使用 numpy where 查找数组的最小值

python - 从数学函数创建图形

python - django - 迁移和模型转换的问题

c++ - 是否可以禁用编译器警告 C4503?

gcc - 为什么 GCC 4.2.1 在某些情况下会忽略 #pragma GCC diagnostic ignored "-Wcast-qual"?