Skip to content

gh-139847: Add PyType_Lookup() function#139848

Closed
vstinner wants to merge 9 commits into
python:mainfrom
vstinner:type_lookup
Closed

gh-139847: Add PyType_Lookup() function#139848
vstinner wants to merge 9 commits into
python:mainfrom
vstinner:type_lookup

Conversation

@vstinner

@vstinner vstinner commented Oct 9, 2025

Copy link
Copy Markdown
Member

@vstinner vstinner added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-C-API labels Oct 9, 2025
@vstinner vstinner removed the type-feature A feature request or enhancement label Oct 9, 2025
Comment thread Doc/c-api/type.rst Outdated
vstinner and others added 2 commits October 9, 2025 20:49
Co-authored-by: Sam Gross <colesbury@gmail.com>
@vstinner vstinner added type-feature A feature request or enhancement awaiting merge labels Oct 9, 2025
@vstinner

vstinner commented Oct 9, 2025

Copy link
Copy Markdown
Member Author

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.

Comment thread Doc/whatsnew/3.15.rst Outdated
Comment thread Modules/_testcapi/type.c
@vstinner

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member Author

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

@encukou

encukou commented Oct 14, 2025

Copy link
Copy Markdown
Member

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?

Add Python pseudo-code in the doc.
@vstinner

Copy link
Copy Markdown
Member Author

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.

Comment thread Doc/c-api/type.rst Outdated
Co-authored-by: Petr Viktorin <encukou@gmail.com>
@vstinner

Copy link
Copy Markdown
Member Author

The issue was closed, so I close the PR as well: #139847 (comment).

@vstinner vstinner closed this Feb 10, 2026
@vstinner
vstinner deleted the type_lookup branch July 10, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review awaiting merge interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-C-API type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants