Pragmas in python

前端 未结 2 828
醉酒成梦
醉酒成梦 2021-02-01 12:23

I\'m reading bottle.py source code. It\'s a web framework, with only 3000+ lines python code. So cool.

I found some code like this:

class ServerAdapter(o         


        
相关标签:
2条回答
  • 2021-02-01 13:03

    It is apparenly related to the 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.

    That exact # pragma: no cover is the hint that the part of code should be ignored by the tool -- see Excluding code from coverage .

    0 讨论(0)
  • 2021-02-01 13:10

    For Python, it's simply a comment. It might be an annotation targeted at some external tool, which reads and analyzes Python code, similar, for example, to doctest's #doctest: +ELLIPSIS annotations or PyLint's # pylint: disable=W0613 style annotations.

    0 讨论(0)
提交回复
热议问题