In 2.6 but not in 3.0 RC2: x = bytearray(b'abc') y = x.replace(b'abc', b'bar', 0) id(x) == id(y) In 2.6 and in 3.0 RC2: t = bytearray() for i in range(256): t.append(i) x = bytearray(b'') y = x.translate(t) id(x) == id(y)
I verified that the results for 3.0c2 are False (correct) and True (bug). Guido today on pydev: this is a bug IMO and we should fix it in 2.6.1 and 3.0rc3
Here's another patch for 2.7/2.6 that handles the translation problem correctly. It appears that the return_self problem isn't present in 3.0, but that can be handled in the merge.
Since 3.0c2 bytearray.translate() *does* return self with no change, I don't understand your first comment, unless you meant 'is' instead of 'is not'. But I presume merging forward will fix it.
And it turns out I should have looked at the other patch instead. =) The missing comment from the test still holds. I also think you did not need to cut out the fast path from translate as much as you did when there is no deletion. It's still legitimate to goto 'done' if you put back the work being done in the 'if' statement. You can see my attached patch to see what I mean. Otherwise it looks good.