homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author arigo
Recipients
Date 2005年12月26日.16:09:50
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
This is a fix for bug #1355842, with a comprehensive
test checking that implementing a binary special method
but returning NotImplemented does indeed cause a
TypeError to be raised. In addition to the case
reported in #1355842 (x+=y) the test found another case
where NotImplemented was just returned (A()*5), a case
where an OverflowError or ValueError was raised instead
of TypeError (A()*large_integer), and a case where an
unexpected AttributeError was raised (5*A()).
The proposed patch also reverts the changes done in svn
revisions 25556-25557 corresponding to bug #516727,
because it makes that fix unnecessary by adopting a
more radical approach.
All the problems are due to hard-to-control
interactions between the various PyTypeObject slots for
addition and multiplication (nb_add vs sq_concat,
nb_multiply vs sq_repeat). The approach of the present
patch is to not define sq_concat, sq_repeat,
sq_inplace_concat and sq_inplace_repeat slots *at all*
for user-defined types, even if they have __add__ and
__mul__ methods. This is the only sane solution I
found, specially with respect to the
OverflowError/ValueError problem (caused by trying to
convert the integer to a C int in order to try to call
sq_repeat). It is also consistent with the behavior of
instances of old-style classes -- the InstanceType did
not define sq_concat and sq_repeat, either.
I'll propose a redefinition of operator.concat() and
operator.repeat() on python-dev.
History
Date User Action Args
2007年08月23日 15:45:06adminlinkissue1390657 messages
2007年08月23日 15:45:06admincreate

AltStyle によって変換されたページ (->オリジナル) /