Thomas Kluyver <tho...@kluyver.me.uk> added the comment:
The 'single' option to compile() means it's run like at a REPL, calling displayhook if it's an expression returning a value. But warnings shouldn't go through the displayhook, as far as I know: >>> from contextlib import redirect_stdout, redirect_stderr >>> from io import StringIO >>> sio = StringIO() >>> with redirect_stderr(sio): ... exec(compile('import warnings; warnings.warn(""" \' " """)', 'dummyfile', 'single')) ... >>> print(sio.getvalue()) __main__:1: UserWarning: ' " ---------- _______________________________________ 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