sphinx-doc/sphinx

Support variable definitions in literalinclude's pyobject option

Open

#6,119 建立於 2019年3月1日

在 GitHub 查看
 (2 留言) (1 反應) (0 負責人)Python (1,985 fork)batch import
help wantedmarkuptype:enhancement

倉庫指標

Star
 (5,625 star)
PR 合併指標
 (平均合併 10天 11小時) (30 天內合併 11 個 PR)

描述

The :pyobject: option of the literalinclude directive is great for including only a specific definition of a module. Currently (Sphinx 1.8.4), it supports class and function definitions. I suggest to extend this to also support module-level variable definitions.

An example from my personal use case: I use collections.namedtuple in my code for creating simple record-like classes:

MyClass = namedtuple('MyClass', 'attribute1, attribute2')

Since they don't use a "real" class definition, I cannot show their definition using :pyobject:.

A possible alternative to supporting variable definitions in :pyobject: which might be more flexible would be to support grepping lines using a regex. I could then do

.. literalinclude:: my_module.py
   :regex: ^MyClass\s*=

貢獻者指南