[Python-Dev] Why is nb_inplace_add copied to sq_inplace_concat?

Nick Coghlan ncoghlan at gmail.com
Fri May 17 05:38:21 CEST 2013


On Fri, May 17, 2013 at 9:17 AM, Matt Newell <newellm at blur.com> wrote:
> I don't really understand what the fixup_slot_dispatchers function is doing,
> but it does seem like there must be a bug either in what it's doing, or in
> PyNumber_InPlaceAdd's handling of a NotImplemented return value from
> sq_inplace_concat.

I didn't read your post in detail, but operand precedence in CPython
is known to be broken for types which only populate the sq_* slots
without also populating the corresponding nb_* slots:
http://bugs.python.org/issue11477

The bug doesn't affect types implemented in Python, as the interpreter
always populates both slots (I believe Cython also populated both
slots for types defined that way).

I made one attempt at fixing it (by changing the fallback handling in
abstract.c) but it turned out to be completely unmaintainable (and
didn't really work right anyway). There's another suggested approach
that would likely work better (automatically populating the nb_* slots
with delegation wrappers and losing the fallback code in abstract.c
entirely), but it still needs a patch (the test cases from my failed
attempt may still prove useful, though).

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list