Skip to content

Commit 45e401e

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Update patch documentation
Summary: We have various things in our patches which add new API surface but it's not documented: https://github.com/facebookincubator/cinder/actions/runs/27316517505/job/80698211733 This is just some claude generated documentation. Reviewed By: alexmalyshev Differential Revision: D108635749 fbshipit-source-id: 72ed3150a4b8d59c65fd947fbb086858945af010
1 parent 070753d commit 45e401e

5 files changed

Lines changed: 108 additions & 0 deletions

File tree

Doc/c-api/dict.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,47 @@ Dictionary Objects
386386
:term:`strong reference <strong reference>` (for example, using
387387
:c:func:`Py_NewRef`).
388388
389+
.. c:function:: int PyDict_NextWithError(PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
390+
391+
Similar to :c:func:`PyDict_Next`, but any :ref:`lazy import <lazy-imports>`
392+
placeholder values encountered during iteration are resolved (by performing
393+
the deferred import) before being returned through *pvalue*. Because
394+
resolving a lazy import can execute arbitrary code and fail, this function
395+
may set an exception and return false even when the iteration has not yet
396+
completed. After the loop ends, call :c:func:`PyErr_Occurred` to
397+
distinguish normal completion from an error.
398+
399+
.. note::
400+
401+
This function is specific to Meta's Python build and is only available
402+
when lazy imports support is compiled in.
403+
404+
.. c:function:: Py_ssize_t PyDict_ResolveLazyImports(PyObject *p)
405+
406+
Resolve every :ref:`lazy import <lazy-imports>` placeholder currently stored
407+
in the dictionary *p*, performing the deferred imports so that the dictionary
408+
no longer contains any unresolved lazy values. Return the number of values
409+
that were resolved, or ``-1`` with an exception set if resolving one of them
410+
failed.
411+
412+
.. note::
413+
414+
This function is specific to Meta's Python build and is only available
415+
when lazy imports support is compiled in.
416+
417+
.. c:function:: int PyDict_IsLazyImport(PyObject *p, PyObject *name)
418+
419+
Return ``1`` if the value stored under *name* in dictionary *p* is an
420+
unresolved :ref:`lazy import <lazy-imports>` placeholder, ``0`` if it is a
421+
regular (already resolved) value or is not present, and ``-1`` with an
422+
exception set on error. Unlike a normal lookup, this does not trigger
423+
resolution of the lazy import.
424+
425+
.. note::
426+
427+
This function is specific to Meta's Python build and is only available
428+
when lazy imports support is compiled in.
429+
389430
.. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)
390431
391432
Iterate over mapping object *b* adding key-value pairs to dictionary *a*.

Doc/c-api/exceptions.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,17 @@ Exception types
12181218
.. versionadded:: 3.11
12191219
:c:data:`PyExc_BaseExceptionGroup`.
12201220
1221+
.. c:var:: PyObject *PyExc_ImportCycleError
1222+
1223+
A subclass of :c:data:`PyExc_ImportError` raised when resolving a
1224+
:ref:`lazy import <lazy-imports>` would require importing a module that is
1225+
already in the process of being imported, i.e. an import cycle is detected.
1226+
1227+
.. note::
1228+
1229+
This exception is specific to Meta's Python build and is only available
1230+
when lazy imports support is compiled in.
1231+
12211232
12221233
OSError aliases
12231234
---------------

Doc/c-api/import.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,51 @@ Importing Modules
353353
strings instead of Python :class:`str` objects.
354354
355355
.. versionadded:: 3.14
356+
357+
358+
.. c:function:: PyObject* PyImport_CreateModuleFromInitfunc(PyObject *spec, PyObject* (*initfunc)(void))
359+
360+
Initialize an extension module directly from a module *spec* and its
361+
initialization function *initfunc*, returning a new reference to the
362+
resulting module object, or ``NULL`` with an exception set on failure.
363+
364+
Custom importers can use this to initialize statically linked extension
365+
modules without registering them in the table of built-in modules (see
366+
:c:func:`PyImport_ExtendInittab`). *initfunc* is the module's
367+
``PyInit_<name>`` function and *spec* is the
368+
:class:`~importlib.machinery.ModuleSpec` describing the module.
369+
370+
371+
.. _lazy-imports:
372+
373+
Lazy imports
374+
------------
375+
376+
The following APIs are specific to Meta's Python build. When *lazy imports*
377+
are enabled, the work of importing a module is deferred until the imported
378+
name is first used: an import binds a lightweight placeholder object in the
379+
namespace, and the real import is performed on first lookup of that name.
380+
381+
.. c:function:: PyObject* PyImport_SetLazyImports(PyObject *enabled, PyObject *excluding, PyObject *eager)
382+
383+
Configure lazy imports for the running interpreter. *enabled* is a truth
384+
value controlling whether lazy imports are turned on. *excluding*, if not
385+
``NULL``, is a container of module names that should never be imported
386+
lazily, and *eager*, if not ``NULL``, is a container of module names that
387+
should always be imported eagerly. Return a value reflecting the previous
388+
configuration, or ``NULL`` with an exception set on failure.
389+
390+
.. c:function:: int PyImport_IsLazyImportsEnabled(void)
391+
392+
Return a nonzero value if lazy imports are currently enabled for the running
393+
interpreter, and ``0`` otherwise.
394+
395+
.. c:var:: PyTypeObject PyLazyImport_Type
396+
397+
The type object for lazy import placeholder objects, the objects that stand
398+
in for a not-yet-performed import until the imported name is first used.
399+
400+
.. c:macro:: PyLazyImport_CheckExact(op)
401+
402+
Return non-zero if *op* is exactly a lazy import placeholder object (that is,
403+
its type is :c:data:`PyLazyImport_Type`); this function always succeeds.

Doc/c-api/veryhigh.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ the same library that the Python runtime is using.
343343
:py:mod:`!ast` Python module, which exports these constants under
344344
the same names.
345345
346+
.. c:macro:: PyCF_DISABLE_LAZY_IMPORTS
347+
348+
Compile the code with :ref:`lazy imports <lazy-imports>` disabled, so that
349+
every ``import`` statement in the compiled code is performed eagerly even
350+
when lazy imports are otherwise enabled. This flag is specific to Meta's
351+
Python build.
352+
346353
The "``PyCF``" flags above can be combined with "``CO_FUTURE``" flags such
347354
as :c:macro:`CO_FUTURE_ANNOTATIONS` to enable features normally
348355
selectable using :ref:`future statements <future>`.

Tools/check-c-api-docs/ignored_c_api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ PyException_HEAD
7575
# cpython/pyframe.h
7676
PyUnstable_EXECUTABLE_KINDS
7777
PyUnstable_EXECUTABLE_KIND_BUILTIN_FUNCTION
78+
PyUnstable_EXECUTABLE_KIND_JIT
7879
PyUnstable_EXECUTABLE_KIND_METHOD_DESCRIPTOR
7980
PyUnstable_EXECUTABLE_KIND_PY_FUNCTION
8081
PyUnstable_EXECUTABLE_KIND_SKIP

0 commit comments

Comments
 (0)