Doctests formatting in Docstrings
See original GitHub issueIs your feature request related to a problem? Please describe.
Black currently does not format Doctests in Docstrings. This issues was reported in https://github.com/psf/black/issues/745 which was superseeded by https://github.com/psf/black/issues/144.
As the latter was closed though, nothing was done about the Doctests.
Describe the solution you’d like
I would be keen for black to format Doctest.
For example, given the following Python Doctests code:
>>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
>>> LMS_to_LMS_p_callable = lambda x: x ** 0.43
>>> matrix_XYZ_to_LMS = np.array(
... [[0.4002, 0.7075, -0.0807],
... [-0.2280, 1.1500, 0.0612],
... [0.0000, 0.0000, 0.9184]])
>>> matrix_LMS_p_to_Iab = np.array(
... [[0.4000, 0.4000, 0.2000],
... [4.4550, -4.8510, 0.3960],
... [0.8056, 0.3572, -1.1628]])
>>> XYZ_to_Iab(
... XYZ, LMS_to_LMS_p_callable, matrix_XYZ_to_LMS, matrix_LMS_p_to_Iab)
black could produce the following output:
>>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
>>> LMS_to_LMS_p_callable = lambda x: x**0.43
>>> matrix_XYZ_to_LMS = np.array(
... [
... [0.4002, 0.7075, -0.0807],
... [-0.2280, 1.1500, 0.0612],
... [0.0000, 0.0000, 0.9184],
... ]
... )
>>> matrix_LMS_p_to_Iab = np.array(
... [
... [0.4000, 0.4000, 0.2000],
... [4.4550, -4.8510, 0.3960],
... [0.8056, 0.3572, -1.1628],
... ]
... )
>>> XYZ_to_Iab(
... XYZ, LMS_to_LMS_p_callable, matrix_XYZ_to_LMS, matrix_LMS_p_to_Iab
... )
Describe alternatives you’ve considered
I’m manually formatting the code.
Additional context
N/A
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7
Top Results From Across the Web
doctest — Test interactive Python examples — Python 3.11.1 ...
There are several common ways to use doctest: To check that a module's docstrings are up-to-date by verifying that all interactive examples still...
Read more >How To Write Doctests in Python - DigitalOcean
Here, we'll add docstrings for the two arguments that are passed to the function and the value that is returned. The docstring will...
Read more >Example Google Style Python Docstrings - Napoleon
Examples: Examples should be written in doctest format, and should illustrate how to use the function. >>> print([i for i in example_generator(4)]) [0,...
Read more >Python's doctest: Document and Test Your Code at Once
Write doctest tests in your code's documentation and docstrings ... This last line has the following general format: ***Test Failed*** N ...
Read more >Creating Python Function docstrings and Running doctests
What information goes into a Python function docstring ? How can you create tests within your docstrings, that can be checked with doctests...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
However, blackdoc works on python files. Depending on where you are placing doctests, you may need both packages.
I’d be willing to consider advertising some of these tools in, say, our “integrations”!