[issue32509] doctest syntax ambiguity between continuation line and ellipsis
Steven D'Aprano
report at bugs.python.org
Sun Jan 7 03:36:17 EST 2018
Steven D'Aprano <steve+python at pearwood.info> added the comment:
Tim Peters said:
> Right, "..." immediately after a ">>>" line is taken to indicate a code continuation line, and there's no way to stop that short of rewriting the parser.
I haven't gone through the source in detail, but it seems to me that we could change OutputChecker.check_output to support this without touching the parser.
Ignoring issues of backwards compatibility for the moment, suppose we accept either '...' or '<ELLIPSIS>' as the wild card in the output section. Jason's example would then become:
>>> print(res) # docstring: +ELLIPSIS
<ELLIPSIS>
d41d8cd98f00b204e9800998ecf8427e __init__.py
...
check_output could replace the substring '<ELLIPSIS>' with three dots before doing anything else, and Bob's yer uncle.
Or in this case, Uncle Timmy's yer uncle :-)
There's probably a million details I haven't thought of, but it seems like a promising approach to me. I did a quick hack of doctest, adding
want = want.replace('<ELLIPSIS>', '...')
to the start of OutputChecker.check_output and it seems to work.
If this is acceptable, we'll probably need a directive to activate it, for the sake of backwards compatibility.
Thoughts?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32509>
_______________________________________
More information about the Python-bugs-list
mailing list