Skip to content

Commit 92ae158

Browse files
[3.13] gh-141004: Document Py_func_type_input (GH-141273) (GH-141299)
gh-141004: Document `Py_func_type_input` (GH-141273) (cherry picked from commit 8dd8498) Co-authored-by: Peter Bierma <[email protected]>
1 parent 2dd8812 commit 92ae158

File tree

1 file changed

+55
-32
lines changed

1 file changed

+55
-32
lines changed

Doc/c-api/veryhigh.rst

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ the interpreter.
1313

1414
Several of these functions accept a start symbol from the grammar as a
1515
parameter. The available start symbols are :c:data:`Py_eval_input`,
16-
:c:data:`Py_file_input`, and :c:data:`Py_single_input`. These are described
17-
following the functions which accept them as parameters.
16+
:c:data:`Py_file_input`, :c:data:`Py_single_input`, and
17+
:c:data:`Py_func_type_input`. These are described following the functions
18+
which accept them as parameters.
1819

1920
Note also that several of these functions take :c:expr:`FILE*` parameters. One
2021
particular issue which needs to be handled carefully is that the :c:type:`FILE`
@@ -183,8 +184,7 @@ the same library that the Python runtime is using.
183184
objects *globals* and *locals* with the compiler flags specified by
184185
*flags*. *globals* must be a dictionary; *locals* can be any object
185186
that implements the mapping protocol. The parameter *start* specifies
186-
the start symbol and must one of the following:
187-
:c:data:`Py_eval_input`, :c:data:`Py_file_input`, or :c:data:`Py_single_input`.
187+
the start symbol and must one of the :ref:`available start symbols <start-symbols>`.
188188
189189
Returns the result of executing the code as a Python object, or ``NULL`` if an
190190
exception was raised.
@@ -233,8 +233,8 @@ the same library that the Python runtime is using.
233233
234234
Parse and compile the Python source code in *str*, returning the resulting code
235235
object. The start symbol is given by *start*; this can be used to constrain the
236-
code which can be compiled and should be :c:data:`Py_eval_input`,
237-
:c:data:`Py_file_input`, or :c:data:`Py_single_input`. The filename specified by
236+
code which can be compiled and should be :ref:`available start symbols
237+
<start-symbols>`. The filename specified by
238238
*filename* is used to construct the code object and may appear in tracebacks or
239239
:exc:`SyntaxError` exception messages. This returns ``NULL`` if the code
240240
cannot be parsed or compiled.
@@ -297,32 +297,6 @@ the same library that the Python runtime is using.
297297
true on success, false on failure.
298298
299299
300-
.. c:var:: int Py_eval_input
301-
302-
.. index:: single: Py_CompileString (C function)
303-
304-
The start symbol from the Python grammar for isolated expressions; for use with
305-
:c:func:`Py_CompileString`.
306-
307-
308-
.. c:var:: int Py_file_input
309-
310-
.. index:: single: Py_CompileString (C function)
311-
312-
The start symbol from the Python grammar for sequences of statements as read
313-
from a file or other source; for use with :c:func:`Py_CompileString`. This is
314-
the symbol to use when compiling arbitrarily long Python source code.
315-
316-
317-
.. c:var:: int Py_single_input
318-
319-
.. index:: single: Py_CompileString (C function)
320-
321-
The start symbol from the Python grammar for a single statement; for use with
322-
:c:func:`Py_CompileString`. This is the symbol used for the interactive
323-
interpreter loop.
324-
325-
326300
.. c:struct:: PyCompilerFlags
327301
328302
This is the structure used to hold compiler flags. In cases where code is only
@@ -366,3 +340,52 @@ the same library that the Python runtime is using.
366340
as :c:macro:`CO_FUTURE_ANNOTATIONS` to enable features normally
367341
selectable using :ref:`future statements <future>`.
368342
See :ref:`c_codeobject_flags` for a complete list.
343+
344+
345+
.. _start-symbols:
346+
347+
Available start symbols
348+
^^^^^^^^^^^^^^^^^^^^^^^
349+
350+
351+
.. c:var:: int Py_eval_input
352+
353+
.. index:: single: Py_CompileString (C function)
354+
355+
The start symbol from the Python grammar for isolated expressions; for use with
356+
:c:func:`Py_CompileString`.
357+
358+
359+
.. c:var:: int Py_file_input
360+
361+
.. index:: single: Py_CompileString (C function)
362+
363+
The start symbol from the Python grammar for sequences of statements as read
364+
from a file or other source; for use with :c:func:`Py_CompileString`. This is
365+
the symbol to use when compiling arbitrarily long Python source code.
366+
367+
368+
.. c:var:: int Py_single_input
369+
370+
.. index:: single: Py_CompileString (C function)
371+
372+
The start symbol from the Python grammar for a single statement; for use with
373+
:c:func:`Py_CompileString`. This is the symbol used for the interactive
374+
interpreter loop.
375+
376+
377+
.. c:var:: int Py_func_type_input
378+
379+
.. index:: single: Py_CompileString (C function)
380+
381+
The start symbol from the Python grammar for a function type; for use with
382+
:c:func:`Py_CompileString`. This is used to parse "signature type comments"
383+
from :pep:`484`.
384+
385+
This requires the :c:macro:`PyCF_ONLY_AST` flag to be set.
386+
387+
.. seealso::
388+
* :py:class:`ast.FunctionType`
389+
* :pep:`484`
390+
391+
.. versionadded:: 3.8

0 commit comments

Comments
 (0)