Message340793
The application of repr() (or a repr()-equivalent) appears to occur as some part of the exec(compile(...)) call within doctest (https://github.com/python/cpython/blob/4f5a3493b534a95fbb01d593b1ffe320db6b395e/Lib/doctest.py#L1328-L1329).
On 3.6.6, in REPL:
```
>>> from contextlib import redirect_stdout
>>> from io import StringIO
>>> sio = StringIO()
>>> with redirect_stdout(sio):
... exec(compile('""" \' " """', 'dummyfile', 'single'))
...
>>> output = sio.getvalue()
>>> output
'\' \\\' " \'\n'
```
Also 3.6.6, at Win cmd:
```
>type exec_compile.py
from contextlib import redirect_stdout
from io import StringIO
exec(compile('""" \' " """', 'dummyfile', 'single'))
sio = StringIO()
with redirect_stdout(sio):
exec(compile('""" \' " """', 'dummyfile', 'single'))
output = sio.getvalue()
assert output == '\' \\\' " \'\n'
>python exec_compile.py
' \' " '
>
```
It *looks* like exec() executes the compile()'d source as if it were typed into a REPL -- IOW, any unassigned non-None return value X gets pushed to stdout as repr(X). This is then what the doctest self._fakeout captures for comparison to the 'want' of the example. |
|
Date |
User |
Action |
Args |
2019-04-24 17:10:31 | bskinn | set | recipients:
+ bskinn, brett.cannon, takluyver, xtreak |
2019-04-24 17:10:31 | bskinn | set | messageid: <1556125831.25.0.951394630369.issue36695@roundup.psfhosted.org> |
2019-04-24 17:10:31 | bskinn | link | issue36695 messages |
2019-04-24 17:10:31 | bskinn | create | |
|