Skip to content

Commit 2cc877c

Browse files
vstinnerencukou
andauthored
Update Doc/c-api/type.rst
Co-authored-by: Petr Viktorin <[email protected]>
1 parent 1290171 commit 2cc877c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Doc/c-api/type.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,25 @@ Type Objects
319319
* If not found, set *\*attr* to ``NULL`` and return ``0``.
320320
* On error, set an exception and return ``-1``.
321321
322-
Python pseudo-code (return :exc:`AttributeError` if not found instead of
323-
raising an exception)::
322+
Python pseudo-code::
324323
325324
def PyType_Lookup(type, name):
326325
if not isinstance(name, str):
327326
raise TypeError
328327
329-
for klass in type.mro():
328+
for superclass in type.mro():
329+
superclass_dict = superclass.__dict__
330330
try:
331-
return klass.__dict__[name]
331+
return superclass_dict[name]
332332
except KeyError:
333333
pass
334334
335335
# not found
336-
return AttributeError
336+
return NULL
337+
338+
Note that this function uses :c:member:`~PyTypeObject.tp_dict` and
339+
:c:member:`~PyTypeObject.tp_mro` directly; it does not look up
340+
``__dict__`` and ``mro`` as Python attributes.
337341
338342
.. versionadded:: next
339343

0 commit comments

Comments
 (0)