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