You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an attribute lookup fails, Python spends a significant chunk of CPU
cycles formatting and then raising an exception.
The ``nb::getattr(object, key, default)`` API provides a fallback
``default`` value in the case of an error. The expense of raising an
exception is therefore not wanted here.
This commit avoids this exception by
- using the new ``PyObject_GetOptionalAttr()`` function on Python 3.13+
- using an internal ``_PyObject_LookupAttr()`` API before Python 3.13.
- on the 3.12 stable API, using ``PyObject_HasAttr()`` before doing the lookup.
0 commit comments