gh-139847: Add PyType_Lookup() function by vstinner · Pull Request #139848 · python/cpython

@vstinner

@vstinner vstinner commented

Oct 9, 2025

edited by github-actions bot

Loading

@vstinner

@vstinner

colesbury

Co-authored-by: Sam Gross <colesbury@gmail.com>

@vstinner

@vstinner

Check labels / Unresolved review (pull_request): Failing after 6s

The CI fails with:

Error: Label error. Requires exactly 1 of: awaiting merge. Found: type-feature, awaiting core review, interpreter-core, topic-C-API

I added the awaiting merge label to repair this CI.

@vstinner

efimov-mikhail

efimov-mikhail

@vstinner

@vstinner

@vstinner

I reverted changes to schedule _PyType_Lookup() and _PyType_LookupRef() removal, just to make this PR easier to review and more "atomic". I prefer to write a separated PR for the removal.

@vstinner

@encukou: So what do you think of exposing this PyType function?

@encukou

I think there's benefit to exposing this but we need to do it carefully. The operation is different from getattr in surprising ways. The docs & tests should mention details -- not invoking descriptors or metaclass getattr. It might also be good for the docs to add an example of where Python uses this operaton, and/or equivalent Python code.

“Lookup” is a new term in the public C API; are we sure this is the right operation for the name?

@vstinner

Add Python pseudo-code in the doc.

@vstinner

The docs & tests should mention details -- not invoking descriptors or metaclass getattr.

Good idea. I added tests for that and completed the doc.

It might also be good for the docs to add an example of where Python uses this operaton, and/or equivalent Python code.

I added Python pseudo-code to the doc.

encukou

@vstinner @encukou

Co-authored-by: Petr Viktorin <encukou@gmail.com>

@vstinner