question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doctests formatting in Docstrings

See original GitHub issue

Is 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:open
  • Created a year ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
adam-grant-hendrycommented, Jul 3, 2022

However, blackdoc works on python files. Depending on where you are placing doctests, you may need both packages.

0reactions
felix-hildencommented, Jul 4, 2022

I’d be willing to consider advertising some of these tools in, say, our “integrations”!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found