Repository navigation
Update doctect SyntaxErrors for location range #89412
Description
Activity
It seems like fine grained error locations do not work in failed doctest traceback output:
version 3.11.0a0
file contents:
------------------def a(x): """ >>> 1 1 1 """ import doctest doctest.testmod()
OUTPUT
-------Failed example: 1 1 Exception raised: Traceback (most recent call last): File "/Users/ak/opensource/cpython/Lib/doctest.py", line 1348, in __run exec(compile(example.source, filename, "single", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<doctest __main__.a[0]>", line 1 1 1 ^ SyntaxError: invalid syntax. Perhaps you forgot a comma?The location in doctests that causes this:
Line 1348 in 5846c9b
exec(compile(example.source, filename, "single", - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)testsTests in the Lib/test dirTests in the Lib/test dir3.11only security fixesonly security fixestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Sep 20, 2021 I've ran into this when looking at doctest docs, the issue is that they use the old example where a single column is highlighted, I want to update it to explain why doctest output differs from the one you get from REPL, but I probably need to understand why it happens to provide a good explanation.
Alternatively this may be fixed to be consistent if it's easy enough to do.
Hummmm, could you explain a bit more in detail what is the expected output? I can see highlighting in the exec call that you pasted:
exec(compile(example.source, filename, "single", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The fact that you see those "^^^^^^" indicate that is working no? What is missing?
Sorry, I should have noted I’m referring to the line 1 1
Which is underlined by a single caret, but on the command line it has 3
carets as expected.Ah, but that is a different issue. This is not PEP-657, this is a SyntaxError, so is related how those are printed, which I think is separared.
Can you try a doctest that fails on something that is not a SyntaxError.
Something like:
>>> def foo(x): ... return x + 42
>> foo(None)
Pablo: that works fine, thanks!
I will look into updating the doctest docs, and will close this issue later
today ( or you can close it if you like).26 remaining items
- added a commit that references this issue
on Jun 5, 2023 - added 3 commits that reference this issue
on Jun 5, 2023
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs