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
NotImplemented->TypeError in __add__ and __mul__ #42733
Comments
This is a fix for bug bpo-1355842, with a comprehensive The proposed patch also reverts the changes done in svn All the problems are due to hard-to-control I'll propose a redefinition of operator.concat() and |
Logged In: YES Attached a second patch, extending PySequence_Repeat() and In 2.4 and HEAD, it works with new-style instances defining Compatibility note: PySequence_Concat/Repeat() are mostly The patch also addresses PySequence_InPlaceConcat/Repeat() |
Logged In: YES Your change to abstract.c that adds "result = Small nits: why not remove the SLOT1 lines from typeobject.c The changes to PySequence_* look correct to me as well. |
Logged In: YES Thanks for the comments about the comments, I will fix them. I don't understand the note about abstract.c, though. |
Logged In: YES I'm not sure what Py_NotImplemented check you are referring |
Logged In: YES Haven't looked at the patches, but your comment "The patch We have the _testcapimodule.c for doing C API tests. Do you also address the problem I posted to python-dev ? """...the following code #define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, OPSTR,
ROPSTR) \
static PyObject * \
FUNCNAME(PyObject *self, PyObject *other) \
{ \
static PyObject *cache_str, *rcache_str; \
int do_other = self->ob_type != other->ob_type && \
other->ob_type->tp_as_number != NULL && \
other->ob_type->tp_as_number->SLOTNAME == TESTFUNC; \
if (self->ob_type->tp_as_number != NULL && \
self->ob_type->tp_as_number->SLOTNAME == TESTFUNC) { \
PyObject *r; \
if (do_other && \
PyType_IsSubtype(other->ob_type, self->ob_type) && \
method_is_overloaded(self, other, ROPSTR)) { \
r = call_maybe( \
other, ROPSTR, &rcache_str, "(O)", self); \
if (r != Py_NotImplemented) \
return r; \
Py_DECREF(r); \
do_other = 0; \
} \
r = call_maybe( \
self, OPSTR, &cache_str, "(O)", other); \
if (r != Py_NotImplemented || \
other->ob_type == self->ob_type) \
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If both types are of the same type, then a NotImplemented
returng
value would be returned.
return r; \
Py_DECREF(r); \
} \
if (do_other) { \
return call_maybe( \
other, ROPSTR, &rcache_str, "(O)", self); \
} \
Py_INCREF(Py_NotImplemented); \
return Py_NotImplemented; \
} """ |
Logged In: YES Thanks for the reminder! It doesn't change the fact that About the python-dev post, see my python-dev answer: it's (Updated patch to come...) |
Logged In: YES Improved the comments and checked in as r41842. I have tested PySequence_InPlace*() "manually". I am |
Logged In: YES Checked in new built-ins operator.ixxx(), with docs and tests. |
Logged In: YES Back-ported to 2.4 as r42511. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: