This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bskinn
Recipients brett.cannon, bskinn, takluyver, xtreak
Date 2019-04-24.17:10:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1556125831.25.0.951394630369.issue36695@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-04-24 17:10:31bskinnsetrecipients: + bskinn, brett.cannon, takluyver, xtreak
2019-04-24 17:10:31bskinnsetmessageid: <1556125831.25.0.951394630369.issue36695@roundup.psfhosted.org>
2019-04-24 17:10:31bskinnlinkissue36695 messages
2019-04-24 17:10:31bskinncreate