bundles / papyri 0.0.10 / papyri / gen / Gen / get_example_data
function
papyri.gen:Gen.get_example_data
source: /papyri/gen.py:863
Signature
def get_example_data(self, example_section: Any, *, obj: Any, qa: str, config: Config, log: logging.Logger) → tuple[Section, list[Any]]Summary
Extract example section data from a NumpyDocString
Extended Summary
One of the section in numpydoc is "examples" that usually consist of number of paragraphs, interleaved with examples starting with >>> and ...,
This attempts to parse this into structured data, with text, input and output as well as to infer the types of each token in the input examples.
This is currently relatively limited as the inference does not work across code blocks.
Parameters
example_sectionThe example section of a numpydoc parsed docstring
objThe current object. It is common for the current object/function to not have to be imported imported in docstrings. This should become a high level option at some point. Note that for method classes, the class should be made available but currently is not.
qa: strThe fully qualified name of current object
config: ConfigCurrent configuration
logLogger instance
Notes
We do not yet properly handle explicit exceptions in examples, and those are seen as Papyri failures.
The capturing of matplotlib figures is also limited.
Examples
Those are self examples, generating papyri documentation with papyri should be able to handle the following A simple input, should be execute and output should be shown if --exec option is set1+1
✗2
2+2
✓4Output with Syntax error should be marked as so.
[this is syntax error]
⚠ File "<doctest papyri.gen:Gen.get_example_data[0]>", line 1
[this is syntax error]
^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
if matplotlib and numpy available, we shoudl show graph
import matplotlib.pyplot as plt import numpy as np x = np.arange(0, 10, 0.1) plt.plot(x, np.sin(x)) plt.show()⚠
File "<doctest papyri.gen:Gen.get_example_data[0]>", line 1
import matplotlib.pyplot as plt
^
SyntaxError: multiple statements found while compiling a single statement
Note that in the above we use `plt.show`,
but we can configure papyri to automatically detect
when figures are created.Aliases
papyri.gen.Gen.get_example_data