Title: bytearray methods returning self
Type: behavior Stage: needs patch
Components: Versions: Python 3.0, Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: benjamin.peterson, brett.cannon, christian.heimes, dino.viehland, terry.reedy
Priority: release blocker Keywords: needs review, patch

Created on 2008-11-18 21:29 by dino.viehland, last changed 2008-11-19 21:50 by benjamin.peterson. This issue is now closed.

File name Uploaded Description Edit
copies_when_no_change.patch benjamin.peterson, 2008-11-18 21:59
issue4348.diff brett.cannon, 2008-11-19 21:29 Tweak of copies_when_no_change.patch to not cut out a fast path
Messages (9)
msg76012 - (view) Author: Dino Viehland (dino.viehland) * (Python committer) Date: 2008-11-18 21:29
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)
msg76015 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-11-18 21:41
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
msg76016 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-11-18 21:43
I'll try to come up with some tests and a fix later.
msg76017 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-11-18 21:45
Attaching patch.
msg76019 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-11-18 21:59
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.
msg76036 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2008-11-19 02:52
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.
msg76070 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-11-19 20:34
make_sure_to_copy.patch seems fine short of adding a comment to the test
referencing this issue.
msg76072 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-11-19 21:29
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.
msg76074 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-11-19 21:50
Fixed in r67291.
Date User Action Args
2008-11-19 21:50:57benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg76074
2008-11-19 21:29:19brett.cannonsetfiles: + issue4348.diff
messages: + msg76072
2008-11-19 21:22:35benjamin.petersonsetfiles: - make_sure_to_copy.patch
2008-11-19 20:35:04brett.cannonsetassignee: benjamin.peterson
messages: + msg76070
nosy: + brett.cannon
2008-11-19 02:52:53terry.reedysetmessages: + msg76036
2008-11-18 21:59:01benjamin.petersonsetfiles: + copies_when_no_change.patch
messages: + msg76019
2008-11-18 21:45:28benjamin.petersonsetkeywords: + needs review, patch
files: + make_sure_to_copy.patch
messages: + msg76017
nosy: + benjamin.peterson
2008-11-18 21:43:14christian.heimessetnosy: + christian.heimes
messages: + msg76016
stage: needs patch
2008-11-18 21:41:29terry.reedysetnosy: + terry.reedy
messages: + msg76015
2008-11-18 21:33:14benjamin.petersonsetpriority: release blocker
2008-11-18 21:29:14dino.viehlandcreate