Quantcast
Channel: User Louis Maddox - Stack Overflow
Viewing all articles
Browse latest Browse all 51

Answer by Louis Maddox for Python doctest how to match single or double quote in output as opposed to only single quote

$
0
0

I imagine you could achieve this with blacken-docs but I haven't seen an example of this done yet...

Either the approach of:

  • Leave the strings in black standard (double quoted) and find a way to transform the expected output doctest so that it has double quotes (by running black on it somehow?)
  • Run blacken-docs with a single quote setting applied, which also avoids having to think about it yourself

I would instinctively go for the first option because it feels like it solves the problem better, but I expect it is easier to do the latter (and TBH not needing to think about this too much would be a plus).

Upon looking into it though, this doesn't seem supported at present according to this issue, and running blacken-docs on some code which prints a double-quoted __repr__ in a >>> doctest block does not affect said double quoting.

My interpretation of that issue and the other one it links to is that blacken-docs does not support code blocks in the format:

"""Docstring starts here.Code example comes next:>>> from some_module import some_func>>> some_func(1, 2)"1+2""""

I've tried rewriting code in the suggested format:

"""Docstring starts here.Code example comes next:.. code-block:: python>>> from some_module import some_func>>> some_func(1, 2)"1+2""""

but this gives me

code block parse error Cannot parse: 1:0: >>> from some_module import some_func

So I'm not going to use blacken-docs or the more verbose .. code-block: python format, perhaps in time it'll be supported.


Viewing all articles
Browse latest Browse all 51

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>