Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-convert >>> into ... #15

Open
crusaderky opened this issue Apr 28, 2020 · 2 comments
Open

Auto-convert >>> into ... #15

crusaderky opened this issue Apr 28, 2020 · 2 comments

Comments

@crusaderky
Copy link

blackdoc currently crashes on

.. ::

    >>> @d
    >>> def f(): pass

It could automatically replace the second >>> with ...

@keewis
Copy link
Owner

keewis commented Apr 28, 2020

That's not valid doctest, is it? My impression was that doctest is simply code copied from a standard CPython interpreter session with the default prompt and a lone decorator would be a syntax error there (you would always get at least one continuation line, though).

The way the implementation of the doctest format works right now is that it reads lines one-by-one (making sure doctest lines (>>> ) and continuation lines (... ) are grouped together), strips the prompts, applies black and then adds back the prompts and indentation.

Considering that, I don't think adding this is easy since the tool would need to actually parse the code; right now it delegates that entirely to black. Instead, I think improving the error message would be easier (<line number missing in source> is not really helpful).

@KelSolaar
Copy link

That doctest is indeed invalid!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants