Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variable definitions in literalinclude's pyobject option #6119

Open
torfsen opened this issue Mar 1, 2019 · 2 comments
Open

Support variable definitions in literalinclude's pyobject option #6119

torfsen opened this issue Mar 1, 2019 · 2 comments
Labels
help wanted markup type:enhancement enhance or introduce a new feature

Comments

@torfsen
Copy link

torfsen commented Mar 1, 2019

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*=
@torfsen torfsen added the type:enhancement enhance or introduce a new feature label Mar 1, 2019
@tk0miya
Copy link
Member

tk0miya commented Mar 2, 2019

+0 for supporting module level variable: Reasonable. I can accept if somebody sends us a PR.
-1 for adding new option: The directive is already too much complicated. And the notation seems like a program.

@tk0miya tk0miya added this to the some future version milestone Mar 2, 2019
@tk0miya
Copy link
Member

tk0miya commented Mar 2, 2019

Note: we have to investigate the way to know the whole of lines of assignment. An assignment statement might be during mulptiple lines:

foo = (1,
       2,
       3)

@tk0miya tk0miya added the markup label Mar 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted markup type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

2 participants