Enable copy-pasting working example code from numpy style docstrings #6705
Replies: 7 comments
-
It seems vscode-jedi-language-server.mp4 |
Beta Was this translation helpful? Give feedback.
-
Jedi is removing the This block here: |
Beta Was this translation helpful? Give feedback.
-
An alternative would be to use code blocks. Then the >>> isn't necessary to get the code to format like code: def foo_with_doctest():
"""
Some example code:
>>> print(1)
>>> print(2)
""" Gives you this: While this docstring gives you this: def foo_with_codeblock():
"""
Some example code:
.. code-block:: python
print(1)
print(2)
""" |
Beta Was this translation helpful? Give feedback.
-
Thx. We are using |
Beta Was this translation helpful? Give feedback.
-
Selecting code in a code block on Python's website (built with Sphinx) doesn't include the prompts. There's also an option to hide the prompts and outputs. The sphinx-copybutton extension has a lot of knobs one can tweak, for instance, to exclude prompts for copies, which imho is what most people want (you can actually copy/paste code with these prompts in an IPython shell but that looks more like a workaround :) ). See more info on their site https://sphinx-copybutton.readthedocs.io/en/latest/use.html. The good news is that there are many ways VSCode would enhance the UX of these docstrings code blocks :) ! |
Beta Was this translation helpful? Give feedback.
-
If we want to still return the The other alternative would be to eliminate the Transferring to a discussion item for up votes. |
Beta Was this translation helpful? Give feedback.
-
I actually think VS code supporting copyable-code in hover would be a better implementation. Then it would work for other languages. Our markdown has sections like this:
So VS code could use that to put up a custom copy button like the pandas docs do. |
Beta Was this translation helpful? Give feedback.
-
I would like to be able to copy paste working example code from numpy style docstrings. Currently I have to remove
>>>
and...
my self.vs-code.mp4
For context I'm currently contributing improved docstrings to HoloViz Param and we are discussing how we can best include useful example code in the docstrings. Join the discussion holoviz/param#977 (comment).
The problem is would like our example code to be useful in VS Code with Pylance, VS Code with jedi-language-server, PyCharm, Sphinx docs, Jupyter Notebook and many more places.
Beta Was this translation helpful? Give feedback.
All reactions