Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use _PyObject_LookupAttr() instead of PyObject_GetAttr() #106303

Closed
serhiy-storchaka opened this issue Jul 1, 2023 · 0 comments
Closed

Use _PyObject_LookupAttr() instead of PyObject_GetAttr() #106303

serhiy-storchaka opened this issue Jul 1, 2023 · 0 comments
Labels
type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jul 1, 2023

PyObject_GetAttr() followed by PyErr_ExceptionMatches(PyExc_AttributeError) and PyErr_Clear() can be replaced with _PyObject_LookupAttr(). It is faster, because it avoids raising the AttributeError exception which later be caught and dropped at first place. And it leads to simpler code. Most of code already uses _PyObject_LookupAttr(), but some new code was added recently which still use the old idiom.

Linked PRs

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Jul 1, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 1, 2023
serhiy-storchaka added a commit that referenced this issue Jul 9, 2023
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 9, 2023
…t_GetAttr() (pythonGH-106304)

It simplifies and speed up the code..
(cherry picked from commit 93d292c)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jul 9, 2023
…t_GetAttr() (pythonGH-106304)

It simplifies and speed up the code.
(cherry picked from commit 93d292c)

Co-authored-by: Serhiy Storchaka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant