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