Skip to content

Commit 60dc015

Browse files
Apply suggestions from code review
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 1a11bf9 commit 60dc015

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

Doc/c-api/capsule.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ Refer to :ref:`using-capsules` for more information on using these objects.
108108
109109
Import a pointer to a C object from a capsule attribute in a module. The
110110
*name* parameter should specify the full name to the attribute, as in
111-
``module.attribute``. The *name* stored in the capsule must match this
112-
string exactly.
111+
``package.module.attribute``.
112+
Modules are imported if needed,
113+
other components are looked up as attributes.
114+
The *name* stored in the capsule must match this string exactly.
113115
114116
Return the capsule's internal *pointer* on success. On failure, set an
115117
exception and return ``NULL``.
@@ -118,8 +120,7 @@ Refer to :ref:`using-capsules` for more information on using these objects.
118120
*no_block* has no effect anymore.
119121
120122
.. versionchanged:: next
121-
Submodules are now imported if needed,
122-
as in ``package.module.attribute``.
123+
Submodules are now imported if needed.
123124
124125
125126
.. c:function:: int PyCapsule_IsValid(PyObject *capsule, const char *name)

Objects/capsule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,13 @@ PyCapsule_Import(const char *name, int Py_UNUSED(no_block))
232232
{
233233
PyObject *object = NULL;
234234
void *return_value = NULL;
235-
char *trace;
236235
char *name_dup = _PyMem_Strdup(name);
237236

238237
if (!name_dup) {
239238
return PyErr_NoMemory();
240239
}
241240

242-
trace = name_dup;
241+
char *trace = name_dup;
243242
while (1) {
244243
char *dot = strchr(trace, '.');
245244
if (dot) {
@@ -254,8 +253,10 @@ PyCapsule_Import(const char *name, int Py_UNUSED(no_block))
254253
Py_SETREF(object, attr);
255254
}
256255
if (!dot) {
256+
// We are done
257257
break;
258258
}
259+
259260
if (!object) {
260261
object = PyImport_ImportModule(name_dup);
261262
if (!object) {

0 commit comments

Comments
 (0)