Closed as not planned
Description
Crash report
Four separate small code samples break doctest because a newline is misinterpreted.
In all four code samples, the failure follows the newline string, "\n", whether it appears
as a string literal or is assigned to a variable.
CONTEXT 1
- A newline character in a literal string: "\n",
- in an
__init__()
, - in a class,
- that is in a docstring,
- that is inside an outermost class
CAUSES doctest.testmod() to
- raise a ValueError exception,
- diagnose that line 10 of the docstring has inconsistent leading whitespace: '",' -- when there is no inconsistent leading whitespace in the file --
- display a Traceback stack,
- return to the shell prompt with status code 1.
TRACEBACK, context 1
Runable code sample 1 contains a traceback.
Error messages, context 1
- ValueError: line 10 of the docstring for main.F has inconsistent leading whitespace: '",'
- returned to shell prompt with status code 1.
CONTEXT 2
- Assigning a newline character in a literal string to a variable
- in an
__init__()
, - in a class,
- that is in a docstring,
- that is inside an outermost class
CAUSES doctest.testmod() to
- raise a ValueError exception,
- -- NOTE THE LINE NUMBER CHANGE FROM CONTEXT 1--
- diagnose that line 5 of the docstring has inconsistent leading whitespace: '",' -- when there is no inconsistent leading whitespace in the file --
- display a Traceback stack,
- return to the shell prompt with status code 1.
TRACEBACK, context 2
Runable code sample 2 contains a traceback.
Error messages, context 2
- ValueError: line 5 of the docstring for main.F has inconsistent leading whitespace: '"'
- returned to shell prompt with status code 1.
CONTEXT 3
- A newline character in a literal string ("\n"),
- in a function,
- that is in a docstring
CAUSES doctest.testmod() to
- incorrectly interpret string literal "\n" as a line break,
- try a test that was not requested,
- incorrectly expect the test to produce the bottom of function in_it(),
- raise a SyntaxError exception,
- incorrectly detect that line 9 of the docstring has an unterminated string literal -- although there are no unterminated string literals in the file --
- display a Traceback stack,
- return to the shell prompt with status code 0, as if nothing bad happened.
TRACEBACK, context 3
Runable code sample 3 contains both the try/expecting pair and the traceback.
Error messages, context 3
- SyntaxError: unterminated string literal (detected at line 9)
- returned to shell prompt with status code 0.
CONTEXT 4
- Assigning a newline character in a literal string to a variable
- in a function,
- that is in a docstring
CAUSES doctest.testmod() to
- incorrectly interpret string literal "\n" as a line break,
- try a test that was not requested,
- incorrectly expect the test to produce the bottom of function in_it(),
- raise a SyntaxError exception,
- -- NOTE THE LINE NUMBER CHANGE FROM CONTEXT 3--
- incorrectly detect that line 4 of the docstring has an unterminated string literal -- although there are no unterminated string literals in the file --
- display a Traceback stack,
- return to the shell prompt with status code 0, as if nothing bad happened.
TRACEBACK, context 4
Runable code sample 4 contains both the try/expecting pair and the traceback.
Error messages, context 4
- SyntaxError: unterminated string literal (detected at line 4)
- returned to shell prompt with status code 0.
My environment
- CPython versions tested on: Python 3.11.2 (main, Mar 24 2023, 00:28:48) [Clang 14.0.0 (clang-1400.0.29.202)]
- Operating system and architecture: macOS 12.6.5, Intel Core i9
codesample1.tgz
codesample2.tgz
codesample3.tgz
codesample4.tgz