@@ -1690,9 +1690,9 @@ Removed
16901690 that were only being used by the old parser, including `` node.h`` , `` parser.h`` ,
16911691 `` graminit.h`` and `` grammar.h`` .
16921692
1693- * Removed the Public C API functions :c:func: ` PyParser_SimpleParseStringFlags` ,
1694- :c:func: ` PyParser_SimpleParseStringFlagsFilename` ,
1695- :c:func: ` PyParser_SimpleParseFileFlags` and :c:func: ` PyNode_Compile`
1693+ * Removed the Public C API functions `` PyParser_SimpleParseStringFlags` ` ,
1694+ `` PyParser_SimpleParseStringFlagsFilename` ` ,
1695+ `` PyParser_SimpleParseFileFlags`` and `` PyNode_Compile` `
16961696 that were deprecated in 3.9 due to the switch to the new PEG parser.
16971697
16981698* Removed the `` formatter`` module, which was deprecated in Python 3.4 .
@@ -1806,6 +1806,41 @@ Changes in the Python API
18061806 also inherits the current builtins.
18071807 (Contributed by Victor Stinner in :issue:`42990 ` .)
18081808
1809+ Changes in the C API
1810+ --------------------
1811+
1812+ * The C API functions `` PyParser_SimpleParseStringFlags`` ,
1813+ `` PyParser_SimpleParseStringFlagsFilename`` ,
1814+ `` PyParser_SimpleParseFileFlags`` , `` PyNode_Compile`` and the type
1815+ used by these functions, `` struct _node`` , were removed due to the switch
1816+ to the new PEG parser.
1817+
1818+ Source should be now be compiled directly to a code object using, for
1819+ example, :c:func:`Py_CompileString` . The resulting code object can then be
1820+ evaluated using, for example, :c:func:`PyEval_EvalCode` .
1821+
1822+ Specifically:
1823+
1824+ * A call to `` PyParser_SimpleParseStringFlags`` followed by
1825+ `` PyNode_Compile`` can be replaced by calling :c:func:`Py_CompileString` .
1826+
1827+ * There is no direct replacement for `` PyParser_SimpleParseFileFlags`` .
1828+ To compile code from a `` FILE * `` argument, you will need to read
1829+ the file in C and pass the resulting buffer to :c:func:`Py_CompileString` .
1830+
1831+ * To compile a file given a `` char * `` filename, explicitly open the file , read
1832+ it and compile the result. One way to do this is using the :py:mod:`io`
1833+ module with :c:func:`PyImport_ImportModule` , :c:func:`PyObject_CallMethod` ,
1834+ :c:func:`PyBytes_AsString` and :c:func:`Py_CompileString` ,
1835+ as sketched below. (Declarations and error handling are omitted.) ::
1836+
1837+ io_module = Import_ImportModule(" io" );
1838+ fileobject = PyObject_CallMethod(io_module, " open" , " ss" , filename, " rb" );
1839+ source_bytes_object = PyObject_CallMethod(fileobject, " read" , " " );
1840+ result = PyObject_CallMethod(fileobject, " close" , " " );
1841+ source_buf = PyBytes_AsString(source_bytes_object);
1842+ code = Py_CompileString(source_buf, filename, Py_file_input);
1843+
18091844CPython bytecode changes
18101845========================
18111846
0 commit comments