-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
bpo-30509: Clean up calling type slots. #1883
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
bpo-30509: Clean up calling type slots. #1883
Conversation
|
@serhiy-storchaka, thanks for your PR! By analyzing the history of the files in this pull request, we identified @tim-one, @benjaminp and @larryhastings to be potential reviewers. |
Objects/typeobject.c
Outdated
|
|
||
| retval = PyObject_CallFunctionObjArgs(func, ival, NULL); | ||
| Py_DECREF(func); | ||
| retval = call_method(self, &PyId___getitem__, &ival, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change optimizes the __getitem__ slot if I understand correctly, since it handles bound/unbound methods. Good :-) It might be useful to mention it.
About &ival: FYI I removed the _PyObject_CallArg1() macro since it increased the stack usage: https://bugs.python.org/issue28858
Objects/typeobject.c
Outdated
| PyErr_SetObject(PyExc_AttributeError, getitem_str); | ||
| PyObject *retval; | ||
| PyObject *ival = PyLong_FromSsize_t(i); | ||
| if (ival == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP 7 now requires { ... } for if block.
| int unbound; | ||
|
|
||
| func = lookup_method(self, &PyId___hash__, &unbound); | ||
| func = lookup_maybe_method(self, &PyId___hash__, &unbound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok: Error handled below by PyObject_HashNotImplemented().
| PyObject *func, *res; | ||
|
|
||
| func = lookup_method(self, &name_op[op], &unbound); | ||
| func = lookup_maybe_method(self, &name_op[op], &unbound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok: exception ignored, PyErr_Clear().
| _Py_IDENTIFIER(__iter__); | ||
|
|
||
| func = lookup_method(self, &PyId___iter__, &unbound); | ||
| func = lookup_maybe_method(self, &PyId___iter__, &unbound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok: exception replaced below.
| _Py_IDENTIFIER(__aiter__); | ||
|
|
||
| func = lookup_method(self, &PyId___aiter__, &unbound); | ||
| func = lookup_maybe_method(self, &PyId___aiter__, &unbound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok: exception replaced below.
| _Py_IDENTIFIER(__anext__); | ||
|
|
||
| func = lookup_method(self, &PyId___anext__, &unbound); | ||
| func = lookup_maybe_method(self, &PyId___anext__, &unbound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok: exception replaced below.
| if (func == NULL) { | ||
| if (!PyErr_Occurred()) | ||
| PyErr_SetObject(PyExc_AttributeError, name->object); | ||
| func = lookup_method(obj, name, &unbound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok: reuse lookup_method() which handles exceptions the same way.
Objects/typeobject.c
Outdated
| if (!PyErr_Occurred()) | ||
| PyErr_SetObject(PyExc_AttributeError, name->object); | ||
| func = lookup_method(obj, name, &unbound); | ||
| if (func == NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP 7: need { ... }
"braces are strongly preferred" https://www.python.org/dev/peps/pep-0007/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"... but may be omitted where C permits"
| int unbound; | ||
|
|
||
| func = lookup_method(self, &PyId___repr__, &unbound); | ||
| func = lookup_maybe_method(self, &PyId___repr__, &unbound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok: exception ignored using PyErr_Clear().
|
LGTM except of missing { ... } at two places. |
|
AppVeyor failure is unrelated to this change: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a discussion about braces on python-dev to try to clarify the coding style.
In the meanwhile, I don't think that it's worth it to block such nice enhancement: LGTM, I approve it.
No description provided.