Brian Skinn <bsk...@alum.mit.edu> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36695> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com