cpython/Include
Pablo Galindo a77aac4fca
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way:

>>> foo(x, z for z in range(10), t, w)
  File "<stdin>", line 1
    foo(x, z for z in range(10), t, w)
           ^
SyntaxError: Generator expression must be parenthesized

becomes

>>> foo(x, z for z in range(10), t, w)
  File "<stdin>", line 1
    foo(x, z for z in range(10), t, w)
           ^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
2021-04-23 14:27:05 +01:00
..
cpython bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525) 2021-04-23 14:27:05 +01:00
internal bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525) 2021-04-23 14:27:05 +01:00
abstract.h bpo-31861: Add aiter and anext to builtins (#23847) 2021-03-23 15:47:21 -07:00
bltinmodule.h
boolobject.h bpo-43795: PEP-652: Simplify headers for easier static analysis (GH-25483) 2021-04-23 14:14:00 +02:00
bytearrayobject.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
bytesobject.h bpo-42431: Fix outdated bytes comments (GH-23458) 2020-12-03 12:46:16 +02:00
cellobject.h bpo-30459: Cast the result of PyCell_SET to void (GH-23654) 2020-12-07 11:56:20 +01:00
ceval.h bpo-41936. Remove macros Py_ALLOW_RECURSION/Py_END_ALLOW_RECURSION (GH-22552) 2020-10-05 12:32:00 +03:00
classobject.h bpo-39573: PyXXX_Check() macros use Py_IS_TYPE() (GH-18508) 2020-02-14 08:48:12 +01:00
code.h bpo-40421: Add Include/cpython/code.h header file (GH-19756) 2020-04-28 17:07:12 +02:00
codecs.h bpo-41842: Add codecs.unregister() function (GH-22360) 2020-09-28 23:41:11 +02:00
compile.h bpo-35134: Add include/cpython/compile.h (GH-24922) 2021-03-22 09:32:11 +01:00
complexobject.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
context.h bpo-40428: Remove PyTuple_ClearFreeList() function (GH-19769) 2020-04-29 02:29:20 +02:00
datetime.h bpo-30155: Add macros to get tzinfo from datetime instances (GH-21633) 2020-09-23 14:43:45 -04:00
descrobject.h bpo-40170: Convert PyDescr_IsData() to static inline function (GH-24535) 2021-02-16 08:50:00 +01:00
dictobject.h bpo-41845: Move PyObject_GenericGetDict() back into the limited API (GH22646) 2020-10-19 23:47:37 +01:00
dynamic_annotations.h fix instances of consecutive articles (closes #23221) 2015-01-13 09:17:24 -05:00
enumobject.h
errcode.h bpo-40176: Improve error messages for unclosed string literals (GH-19346) 2021-01-20 13:38:47 -08:00
eval.h bpo-42990: Further refactoring of PyEval_ functions. (GH-24368) 2021-02-01 10:42:03 +00:00
exports.h bpo-11410: Standardize and use symbol visibility attributes across POSIX and Windows. (GH-16347) 2019-10-15 08:26:12 +01:00
fileobject.h bpo-41986: Add Py_FileSystemDefaultEncodeErrors and Py_UTF8Mode back to limited API (GH-22621) 2020-10-10 17:09:45 +03:00
fileutils.h bpo-43795: PEP-652: Clean up the stable ABI/limited API (GH-25482) 2021-04-23 14:17:58 +02:00
floatobject.h bpo-40428: Remove PyTuple_ClearFreeList() function (GH-19769) 2020-04-29 02:29:20 +02:00
frameobject.h bpo-40421: Add pyframe.h header file (GH-19755) 2020-04-28 16:32:48 +02:00
funcobject.h bpo-42990: Introduce 'frame constructor' struct to simplify API for PyEval_CodeEval and friends (GH-24298) 2021-01-29 13:24:55 +00:00
genericaliasobject.h bpo-39481: Implementation for PEP 585 (#18239) 2020-04-07 09:50:06 -07:00
genobject.h Delete PyGen_Send (#22663) 2020-10-12 12:10:42 -07:00
import.h bpo-39372: Clean header files of declared interfaces with no implementations (GH-18037) 2020-01-18 03:14:59 +00:00
interpreteridobject.h bpo-36097: Use only public C-API in the_xxsubinterpreters module (adding as necessary). (gh-12359) 2019-03-15 16:35:46 -06:00
intrcheck.h bpo-41713: Remove PyOS_InitInterrupts() function (GH-23342) 2020-11-17 16:22:23 +01:00
iterobject.h bpo-43770: _PyTypes_Init() inits _PyAnextAwaitable_Type (GH-25266) 2021-04-08 09:58:15 +02:00
listobject.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
longintrepr.h bpo-32150: Expand tabs to spaces in C files. (#4583) 2017-11-28 17:56:10 +02:00
longobject.h bpo-42161: Remove private _PyLong_Zero and _PyLong_One (GH-23003) 2020-10-27 21:34:33 +01:00
marshal.h Issue #1772673: The type of char* arguments now changed to const char*. 2013-10-19 21:03:34 +03:00
memoryobject.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
methodobject.h bpo-43688: Fix Py_LIMITED_API version of xxlimited (GH-25135) 2021-04-01 15:09:33 +02:00
modsupport.h bpo-1635741: Add PyModule_AddObjectRef() function (GH-23122) 2020-11-04 13:59:15 +01:00
moduleobject.h bpo-42923: Dump extension modules on fatal error (GH-24207) 2021-01-18 20:47:13 +01:00
namespaceobject.h Issue #26900: Excluded underscored names and other private API from limited API. 2016-09-11 11:03:14 +03:00
object.h bpo-43753: Add Py_Is() and Py_IsNone() functions (GH-25227) 2021-04-11 00:17:39 +02:00
objimpl.h bpo-42519: Replace PyObject_MALLOC() with PyObject_Malloc() (GH-23587) 2020-12-01 10:37:39 +01:00
opcode.h bpo-43683: Handle generator entry in bytecode (GH-25138) 2021-04-06 11:48:59 +01:00
osdefs.h bpo-31904: Add cross-build support for VxWorks RTOS (GH-11968) 2019-02-27 12:09:28 +01:00
osmodule.h Issue #29058: All stable API extensions added after Python 3.2 are now 2016-12-27 14:57:39 +02:00
patchlevel.h Post 3.10.0a7 2021-04-05 18:04:54 +01:00
py_curses.h bpo-39573: Finish converting to new Py_IS_TYPE() macro (GH-18601) 2020-03-04 14:15:20 +01:00
pycapsule.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
pydtrace.d bpo-36842: Implement PEP 578 (GH-12613) 2019-05-23 08:45:22 -07:00
pydtrace.h bpo-36842: Implement PEP 578 (GH-12613) 2019-05-23 08:45:22 -07:00
pyerrors.h bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481) 2021-03-29 12:28:14 +09:00
pyexpat.h bpo-34623: Use XML_SetHashSalt in _elementtree (GH-9146) 2018-09-18 05:38:58 -07:00
pyframe.h bpo-40421: Add PyFrame_GetCode() function (GH-19757) 2020-04-28 19:01:31 +02:00
pyhash.h bpo-43795: PEP-652: Clean up the stable ABI/limited API (GH-25482) 2021-04-23 14:17:58 +02:00
pylifecycle.h bpo-42591: Export missing Py_FrozenMain() symbol (GH-23730) 2020-12-10 18:39:17 +01:00
pymacconfig.h Minor spelling fixes 2016-08-20 08:03:06 +00:00
pymacro.h bpo-41875: Use __builtin_unreachable when possible (GH-22433) 2020-09-29 05:41:23 +09:00
pymath.h bpo-29782: Consolidate _Py_Bit_Length() (GH-20739) 2020-06-15 14:33:48 +02:00
pymem.h bpo-43795: PEP-652: Clean up the stable ABI/limited API (GH-25482) 2021-04-23 14:17:58 +02:00
pyport.h bpo-43795: PEP-652: Simplify headers for easier static analysis (GH-25483) 2021-04-23 14:14:00 +02:00
pystate.h Update code comment re: location of struct _is. (GH-20067) 2020-05-14 19:11:00 -07:00
pystrcmp.h
pystrhex.h bpo-22385: Support output separators in hex methods. (#13578) 2019-05-29 11:46:58 -07:00
pystrtod.h Issue #26331: Implement the parsing part of PEP 515. 2016-09-09 14:57:09 -07:00
Python.h bpo-43244: Remove the pyarena.h header (GH-25007) 2021-03-24 02:23:01 +01:00
pythonrun.h bpo-43868: Remove PyOS_ReadlineFunctionPointer from the stable ABI list (GH-25442) 2021-04-23 14:23:38 +02:00
pythread.h bpo-40089: Add _at_fork_reinit() method to locks (GH-19195) 2020-04-07 23:11:49 +02:00
rangeobject.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
README.rst bpo-43416: Add Include/README.rst (GH-24884) 2021-03-25 17:16:31 +01:00
setobject.h bpo-43277: Add PySet_CheckExact to the C-API (GH-24598) 2021-02-20 18:03:08 +00:00
sliceobject.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00
structmember.h Issue #28761: The fields name and doc of structures PyMemberDef, PyGetSetDef, 2016-11-22 07:58:08 +02:00
structseq.h bpo-38650: Constify PyStructSequence_UnnamedField. (GH-17005) 2019-11-16 18:55:29 +02:00
sysmodule.h bpo-36842: Implement PEP 578 (GH-12613) 2019-05-23 08:45:22 -07:00
token.h bpo-43822: Improve syntax errors for missing commas (GH-25377) 2021-04-15 21:38:45 +01:00
traceback.h bpo-40421: Add pyframe.h header file (GH-19755) 2020-04-28 16:32:48 +02:00
tracemalloc.h bpo-35053: Define _PyTraceMalloc_NewReference in object.h (GH-10107) 2018-10-26 00:01:56 +02:00
tupleobject.h bpo-40428: Remove PyTuple_ClearFreeList() function (GH-19769) 2020-04-29 02:29:20 +02:00
typeslots.h bpo-42085: Introduce dedicated entry in PyAsyncMethods for sending values (#22780) 2020-11-10 12:09:55 -08:00
unicodeobject.h bpo-41784: make PyUnicode_AsUTF8AndSize part of the limited API (GH-22252) 2020-10-19 23:17:50 +01:00
warnings.h bpo-32591: Add native coroutine origin tracking (#5250) 2018-01-21 09:44:07 -05:00
weakrefobject.h bpo-39573: Add Py_IS_TYPE() function (GH-18488) 2020-02-13 18:37:17 +01:00

The Python C API
================

The C API is divided into three sections:

1. ``Include/``
2. ``Include/cpython/``
3. ``Include/internal/``


Include: Limited API
====================

``Include/``, excluding the ``cpython`` and ``internal`` subdirectories,
contains the public Limited API (Application Programming Interface).
The Limited API is a subset of the C API, designed to guarantee ABI
stability across Python 3 versions, and is defined in :pep:`384`.

Guidelines for expanding the Limited API:

- Functions *must not* steal references
- Functions *must not* return borrowed references
- Functions returning references *must* return a strong reference
- Macros should not expose implementation details
- Please start a public discussion before expanding the API
- Functions or macros with a ``_Py`` prefix do not belong in ``Include/``.

It is possible to add a function or macro to the Limited API from a
given Python version.  For example, to add a function to the Limited API
from Python 3.10 and onwards, wrap it with
``#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000``.


Include/cpython: CPython implementation details
===============================================

``Include/cpython/`` contains the public API that is excluded from the
Limited API and the Stable ABI.

Guidelines for expanding the public API:

- Functions *must not* steal references
- Functions *must not* return borrowed references
- Functions returning references *must* return a strong reference


Include/internal: The internal API
==================================


With PyAPI_FUNC or PyAPI_DATA
-----------------------------

Functions or structures in ``Include/internal/`` defined with
``PyAPI_FUNC`` or ``PyAPI_DATA`` are internal functions which are
exposed only for specific use cases like debuggers and profilers.


With the extern keyword
-----------------------

Functions in ``Include/internal/`` defined with the ``extern`` keyword
*must not and can not* be used outside the CPython code base.  Only
built-in stdlib extensions (built with the ``Py_BUILD_CORE_BUILTIN``
macro defined) can use such functions.

When in doubt, new internal C functions should be defined in
``Include/internal`` using the ``extern`` keyword.