summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-28 09:35:52 (GMT)
committerGitHub <noreply@github.com>2021-06-28 09:35:52 (GMT)
commitdc10264eb880ed63fcf42c17057f3f5d879a0a0c (patch)
tree27781db009fe72009bb3453371f687d19ac68488 /Doc/whatsnew
parentf4b31cdbc043449f3df7d291da67bcb3736be0db (diff)
downloadcpython-dc10264eb880ed63fcf42c17057f3f5d879a0a0c.zip
cpython-dc10264eb880ed63fcf42c17057f3f5d879a0a0c.tar.gz
cpython-dc10264eb880ed63fcf42c17057f3f5d879a0a0c.tar.bz2
bpo-40939: Remove documentation for `PyParser_*` & add porting notes (GH-26855) (GH-26898)
I tried to be relatively thorough and give lots of links. One reason is that this wasn't deprecated very long; also it seems people running into this tend to not be familiar with similar APIs. (cherry picked from commit 29987f72650b7cccee4df216c8297e8484a44e6a) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r--Doc/whatsnew/3.10.rst41
1 files changed, 38 insertions, 3 deletions
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 7ed80fb..5e510d8 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -1696,9 +1696,9 @@ Removed
that were only being used by the old parser, including ``node.h``, ``parser.h``,
``graminit.h`` and ``grammar.h``.
-* Removed the Public C API functions :c:func:`PyParser_SimpleParseStringFlags`,
- :c:func:`PyParser_SimpleParseStringFlagsFilename`,
- :c:func:`PyParser_SimpleParseFileFlags` and :c:func:`PyNode_Compile`
+* Removed the Public C API functions ``PyParser_SimpleParseStringFlags``,
+ ``PyParser_SimpleParseStringFlagsFilename``,
+ ``PyParser_SimpleParseFileFlags`` and ``PyNode_Compile``
that were deprecated in 3.9 due to the switch to the new PEG parser.
* Removed the ``formatter`` module, which was deprecated in Python 3.4.
@@ -1812,6 +1812,41 @@ Changes in the Python API
also inherits the current builtins.
(Contributed by Victor Stinner in :issue:`42990`.)
+Changes in the C API
+--------------------
+
+* The C API functions ``PyParser_SimpleParseStringFlags``,
+ ``PyParser_SimpleParseStringFlagsFilename``,
+ ``PyParser_SimpleParseFileFlags``, ``PyNode_Compile`` and the type
+ used by these functions, ``struct _node``, were removed due to the switch
+ to the new PEG parser.
+
+ Source should be now be compiled directly to a code object using, for
+ example, :c:func:`Py_CompileString`. The resulting code object can then be
+ evaluated using, for example, :c:func:`PyEval_EvalCode`.
+
+ Specifically:
+
+ * A call to ``PyParser_SimpleParseStringFlags`` followed by
+ ``PyNode_Compile`` can be replaced by calling :c:func:`Py_CompileString`.
+
+ * There is no direct replacement for ``PyParser_SimpleParseFileFlags``.
+ To compile code from a ``FILE *`` argument, you will need to read
+ the file in C and pass the resulting buffer to :c:func:`Py_CompileString`.
+
+ * To compile a file given a ``char *`` filename, explicitly open the file, read
+ it and compile the result. One way to do this is using the :py:mod:`io`
+ module with :c:func:`PyImport_ImportModule`, :c:func:`PyObject_CallMethod`,
+ :c:func:`PyBytes_AsString` and :c:func:`Py_CompileString`,
+ as sketched below. (Declarations and error handling are omitted.) ::
+
+ io_module = Import_ImportModule("io");
+ fileobject = PyObject_CallMethod(io_module, "open", "ss", filename, "rb");
+ source_bytes_object = PyObject_CallMethod(fileobject, "read", "");
+ result = PyObject_CallMethod(fileobject, "close", "");
+ source_buf = PyBytes_AsString(source_bytes_object);
+ code = Py_CompileString(source_buf, filename, Py_file_input);
+
CPython bytecode changes
========================