Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

No description provided.

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label May 31, 2017
@serhiy-storchaka serhiy-storchaka requested a review from vstinner May 31, 2017 06:47
@mention-bot
Copy link

@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.


retval = PyObject_CallFunctionObjArgs(func, ival, NULL);
Py_DECREF(func);
retval = call_method(self, &PyId___getitem__, &ival, 1);
Copy link
Member

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

PyErr_SetObject(PyExc_AttributeError, getitem_str);
PyObject *retval;
PyObject *ival = PyLong_FromSsize_t(i);
if (ival == NULL)
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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.

if (!PyErr_Occurred())
PyErr_SetObject(PyExc_AttributeError, name->object);
func = lookup_method(obj, name, &unbound);
if (func == NULL)
Copy link
Member

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/

Copy link
Member Author

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);
Copy link
Member

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().

@vstinner
Copy link
Member

LGTM except of missing { ... } at two places.

@vstinner
Copy link
Member

Copy link
Member

@vstinner vstinner left a 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.

@serhiy-storchaka serhiy-storchaka merged commit 4e624ca into python:master Jun 1, 2017
@serhiy-storchaka serhiy-storchaka deleted the type-slot-calls-cleanup branch June 1, 2017 05:18
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

Successfully merging this pull request may close these issues.

4 participants