fix iadd pythonization for np/array buffers #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on root-project/root#18768, pinging @wlav cc @guitargeek
Currently, the
iaddimplementation forstd::vectorinPythonize.cxxworks perfectly with Python lists and iterables for which we have anItemGetter.But the second code path for buffers:
CPyCppyy/src/Pythonize.cxx
Lines 444 to 456 in c6d623a
which we hit when i-adding an
array.arrayornp.array, does not work as expected:If I try the equivalent by directly dispatching to
std::vector::insertit works:here, the difference between
x+=yandx.__iadd__(y)leads to unintuitive behaviour: if the users intention is to obtain the resulting iterator when calling insert, they can dod.insert(d.end(), a)which makes more sense than expecting it fromd+=a. When the user does calld+=a, since__iadd__is overriden, operation does not end with the call toVectorIAddwhich should just return the iterator, and thestd::vectord should reflect the change by insertion . Instead, it ends withd = d.__iadd__(a)which reassigns the vector to the returned iterator, losing the vector in the process.This PR fixes this issue by returning
selfinstead.