{ } Raw JSON

bundles / papyri latest / papyri / gen / Gen / get_example_data

function

papyri.gen:Gen.get_example_data

source: /papyri/gen.py :826

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_section

The example section of a numpydoc parsed docstring

obj

The 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 : str

The fully qualified name of current object

config : Config

Current configuration

log

Logger 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 set
1+1
2+2
Output with Syntax error should be marked as so.
[this is syntax error]
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()
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