2

I have the following function and docstring:

def vflip(self):
    """
    Vertically flips the characters on this canvas.

    >>> canvas = Canvas(4, 4)
    >>> canvas.fill('.')
    >>> canvas[0, 0] = 'A'
    >>> canvas[1, 1] = 'B'
    >>> canvas[2, 2] = 'C'
    >>> canvas[3, 3] = 'D'
    >>> print(canvas)
    A...
    .B..
    ..C.
    ...D
    >>> canvas.vflip()
    >>> print(canvas)
    ...D
    ..C.
    .B..
    A...
    """
    for y in range(0, self.height // 2):
        for x in range(0, self.width):
            self._chars[x][y], self._chars[x][self.height - 1 - y] = self._chars[x][self.height - 1 - y], self._chars[x][y]
    self._strDirty = True

Which produces the following error:

Traceback (most recent call last):
  File "__init__.py", line 1332, in <module>
    print(doctest.testmod())
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 1949, in testmod
    for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 932, in find
    self._find(tests, obj, name, module, source_lines, globs, {})
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 995, in _find
    globs, seen)
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 1029, in _find
    globs, seen)
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 982, in _find
    test = self._get_test(obj, name, module, globs, source_lines)
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 1066, in _get_test
    filename, lineno)
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 668, in get_doctest
    return DocTest(self.get_examples(string, name), globs,
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 682, in get_examples
    return [x for x in self.parse(string, name)
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 644, in parse
    self._parse_example(m, name, lineno)
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 702, in _parse_example
    self._check_prompt_blank(source_lines, indent, name, lineno)
  File "C:\Users\Al\AppData\Local\Programs\Python\Python37\lib\doctest.py", line 789, in _check_prompt_blank
    line[indent:indent+3], line))
ValueError: line 17 of the docstring for __main__.Canvas.vflip lacks blank after ...: '...D'

I'm not sure why I'm getting this error. Other StackOverflow posts usually indicate that there's no space between the >>> and the code on that line, but that's not the case here. Why am I getting this error?

1 Answer 1

3

This is a special case, where the output text '...D' mimics the other Python prompt. The interactive shell use >>> as the normal prompt, but any additional lines in a multi-line statement use ... as a secondary prompt. The '...D' is confusing doctest and making it think that this is a prompt.

For example, notice the two prompts in this basic code:

>>> for i in range(5):
...     print('Hello, world!')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.