diff --git a/Doc/builtins/functions.rst b/Doc/builtins/functions.rst index c3cf8e86692520..14e78381804830 100644 --- a/Doc/builtins/functions.rst +++ b/Doc/builtins/functions.rst @@ -352,8 +352,9 @@ are always available. They are listed here in alphabetical order. The *mode* argument specifies what kind of code must be compiled; it can be ``'exec'`` if *source* consists of a sequence of statements, ``'eval'`` if it consists of a single expression, or ``'single'`` if it consists of a single - interactive statement (in the latter case, expression statements that - evaluate to something other than ``None`` will be printed). + interactive statement. When the resulting code object is executed, + expression statements that evaluate to something other than ``None`` are + displayed using :func:`sys.displayhook`. It can also be ``'func_type'`` if *source* consists of a function type signature, for example ``(int) -> str``; see :func:`ast.parse` for more information. This mode requires passing diff --git a/Doc/library/code.rst b/Doc/library/code.rst index 71eb3e8646cd01..e8631e471c54bb 100644 --- a/Doc/library/code.rst +++ b/Doc/library/code.rst @@ -12,6 +12,14 @@ The ``code`` module provides facilities to implement read-eval-print loops in Python. Two classes and convenience functions are included which can be used to build applications which provide an interactive interpreter prompt. +When code compiled in ``'single'`` mode is executed, expression results other +than ``None`` are displayed using :func:`sys.displayhook`, which writes to +:data:`sys.stdout` by default. Syntax errors and tracebacks are displayed using +:meth:`InteractiveInterpreter.write`, which writes to :data:`sys.stderr` by +default. If :func:`sys.excepthook` has been overridden, it is used to display +syntax errors and tracebacks instead. The console's banner and exit message are +also written using :meth:`InteractiveInterpreter.write`. + .. class:: InteractiveInterpreter(locals=None)