Skip to content

gh-144989: Expose special method lookup at Python level#144990

Open
tanloong wants to merge 17 commits intopython:mainfrom
tanloong:expose-lookupspeicalmethod
Open

gh-144989: Expose special method lookup at Python level#144990
tanloong wants to merge 17 commits intopython:mainfrom
tanloong:expose-lookupspeicalmethod

Conversation

@tanloong
Copy link
Contributor

@tanloong tanloong commented Feb 19, 2026

This exposes _PyObject_LookupSpecialMethod() as types.lookup_special_method(obj, attr).

I am not quite sure which one between the two similar funtions in Objects/typeobject.c should be preferred to be exposed: _PyObject_LookupSpecial() or _PyObject_LookupSpecialMethod(). I chose the _PyObject_LookupSpecialMethod() because it is the function that is called by LOAD_SPECIAL. So I suppose using this one is more consistent with the CPython interpreter when parsing with-statements (#144386 (comment)).

However, I am open to adjusting the PR to expose _PyObject_LookupSpecial() instead if that one is more suitable.


📚 Documentation preview 📚: https://cpython-previews--144990.org.readthedocs.build/

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a "What's New in Python 3.15" entry.

@tanloong
Copy link
Contributor Author

@ZeroIntensity Thank you for your review! I've updated the code accordingly. Could you please take another look when you have time? Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments