From 2ca97979fb2e815d9d6bee2efe680a39fb72cb74 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Mon, 11 May 2020 21:39:11 -0300 Subject: [PATCH 1/2] Document exec symbol for codeop.compile_command --- Doc/library/code.rst | 4 ++-- Doc/library/codeop.rst | 7 +++++-- Lib/codeop.py | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Doc/library/code.rst b/Doc/library/code.rst index 6708079f778c1a..365fee23f50ebb 100644 --- a/Doc/library/code.rst +++ b/Doc/library/code.rst @@ -56,8 +56,8 @@ build applications which provide an interactive interpreter prompt. *source* is the source string; *filename* is the optional filename from which source was read, defaulting to ``''``; and *symbol* is the optional - grammar start symbol, which should be either ``'single'`` (the default) or - ``'eval'``. + grammar start symbol, which should be either ``'single'`` (the default), ``'eval'`` + or ``'exec'``. Returns a code object (the same as ``compile(source, filename, symbol)``) if the command is complete and valid; ``None`` if the command is incomplete; raises diff --git a/Doc/library/codeop.rst b/Doc/library/codeop.rst index a52d2c62c4fea1..2028f6209bca5c 100644 --- a/Doc/library/codeop.rst +++ b/Doc/library/codeop.rst @@ -43,8 +43,11 @@ To do just the former: :exc:`OverflowError` or :exc:`ValueError` if there is an invalid literal. The *symbol* argument determines whether *source* is compiled as a statement - (``'single'``, the default) or as an :term:`expression` (``'eval'``). Any - other value will cause :exc:`ValueError` to be raised. + (``'single'``, the default), as a sequence of statements (``'exec'``) or + as an :term:`expression` (``'eval'``). Any other value will + cause :exc:`ValueError` to be raised. If *symbol* is ``'single'`` and *source* + is an expression, executing the resulting code object will print a representation + of the object the expression evaluates to unless it evaluates to ``None``. .. note:: diff --git a/Lib/codeop.py b/Lib/codeop.py index 082285f94fe847..835e68c09ba272 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -112,7 +112,8 @@ def compile_command(source, filename="", symbol="single"): source -- the source string; may contain \n characters filename -- optional filename from which source was read; default "" - symbol -- optional grammar start symbol; "single" (default) or "eval" + symbol -- optional grammar start symbol; "single" (default), "exec" + or "eval" Return value / exceptions raised: From f5df35620f0575e1f1dedc4d4a9c12ca6448bd08 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Thu, 14 May 2020 20:33:45 -0300 Subject: [PATCH 2/2] Remove extra statements --- Doc/library/code.rst | 2 +- Doc/library/codeop.rst | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Doc/library/code.rst b/Doc/library/code.rst index 365fee23f50ebb..538e5afc7822aa 100644 --- a/Doc/library/code.rst +++ b/Doc/library/code.rst @@ -56,7 +56,7 @@ build applications which provide an interactive interpreter prompt. *source* is the source string; *filename* is the optional filename from which source was read, defaulting to ``''``; and *symbol* is the optional - grammar start symbol, which should be either ``'single'`` (the default), ``'eval'`` + grammar start symbol, which should be ``'single'`` (the default), ``'eval'`` or ``'exec'``. Returns a code object (the same as ``compile(source, filename, symbol)``) if the diff --git a/Doc/library/codeop.rst b/Doc/library/codeop.rst index 2028f6209bca5c..c66b9d3ec0a26d 100644 --- a/Doc/library/codeop.rst +++ b/Doc/library/codeop.rst @@ -45,9 +45,7 @@ To do just the former: The *symbol* argument determines whether *source* is compiled as a statement (``'single'``, the default), as a sequence of statements (``'exec'``) or as an :term:`expression` (``'eval'``). Any other value will - cause :exc:`ValueError` to be raised. If *symbol* is ``'single'`` and *source* - is an expression, executing the resulting code object will print a representation - of the object the expression evaluates to unless it evaluates to ``None``. + cause :exc:`ValueError` to be raised. .. note::