Uh oh!
There was an error while loading. Please reload this page.
gh-144989: Expose special method lookup at Python level - #144990
gh-144989: Expose special method lookup at Python level#144990tanloong wants to merge 33 commits into
Conversation
ZeroIntensity
left a comment
There was a problem hiding this comment.
This needs a "What's New in Python 3.15" entry.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tanloong
commented
Feb 19, 2026
@ZeroIntensity Thank you for your review! I've updated the code accordingly. Could you please take another look when you have time? Thanks again! |
…ethod; 2. raise AttributeError instead of returning None; 3. add optional `default` parameter, similar to `getattr`: lookup_special(object, name[, default]) 4. There are different opinions on which module should the function be in. Leave it in `types` until there is consensus.
This is temporary as which module should the function be put is not determined yet in the discourse discussion.
This is temporary as which module should the function be put is not determined yet in the discourse discussion.
* Added `default` parameter to `lookup_special` in `types.py` See https://discuss.python.org/t/expose-special-method-lookup-at-python-level/106236 for more. --------- Co-authored-by: JoBe <165585785+JoBeGaming@users.noreply.github.com>
JoBeGaming
commented
Feb 23, 2026
Finally all checks passing :) |
Co-authored-by: JoBe <165585785+JoBeGaming@users.noreply.github.com>
This line of comment is copied from definition of `builtin_getattr` in Python/bltinmodule.c. Make this newly added `_types_lookup_special_impl` easier to be found when doing the Argument Clinic convertion in the future.
Documentation build overview
32 files changed · |
This PR is stale because it has been open for 90 days with no activity. |
This exposes
_PyObject_LookupSpecialMethod()astypes.lookup_special_method(obj, attr).I am not quite sure which one between the two similar funtions in
Objects/typeobject.cshould be preferred to be exposed:_PyObject_LookupSpecial()or_PyObject_LookupSpecialMethod(). I chose the_PyObject_LookupSpecialMethod()because it is the function that is called byLOAD_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.Updated based on the consensus reached by now on discourse discussion:
_PyObject_LookupSpecialinstead of_PyObject_LookupSpecialMethodand accordingly renamed (for now) the function fromlookup_special_methodtolookup_special.AttributeErrorif the special method is not found.defaultparameter similar togetattr.📚 Documentation preview 📚: https://cpython-previews--144990.org.readthedocs.build/