-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
bytearray partition bug #64246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If partition is called with a single byte it works correctly but if called with the equivalent integer it returns the same bytearray with two empty arrays as follows. py> ba = bytearray(range(8)) More background on the thread starting here https://mail.python.org/pipermail/python-list/2013-December/663111.html which refers to bpo-12170. |
Similar bug was in 3.2: >>> ba = bytearray(range(8))
>>> ba[2:6]
bytearray(b'\x02\x03\x04\x05')
>>> ba[2:6] = 2
>>> ba
bytearray(b'\x00\x01\x00\x00\x06\x07') Now it is fixed. |
Bytearray slice assignment bug was fixed in bpo-8401. |
Whatever the change, bytes and bytearray should act the same. >>> b = bytes(range(8))
>>> b
b'\x00\x01\x02\x03\x04\x05\x06\x07'
>>> b.partition(3)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
b.partition(3)
TypeError: expected bytes, bytearray or buffer compatible object As noted in the thread, ba.partition(a) apparently is executed as ba.partition(bytearray(a)) if a is not a bytearray (or maybe not a buffer object). bytearray(3) == bytearray((0,0,0)) and the latter is not in ba and hence the output given is 'correct'. |
I believe that all methods should act the same, but they don't as a result of the work done in bpo-12170. E.g. find will accept integer input but split will not. Given this comment at the top of test_bytes.py "XXX This is a mess. Common tests should be moved to buffer_tests.py, which itself ought to be unified with string_tests.py (and the latter should be modernized).", it looks like a thorough review of the code and tests is in order. |
To answer Mark, even though no longer nosy: In general, sequence methods .count, .index, and .__contains__ take sequence members and only members as arguments. Unicode sequences are exceptional because codepoints are not Python objects, so string subsequences must be used instead. Byte-like sequences are also exceptional in that both members and subsequences are accepted for these methods. String-like sequence methods .split and .partition take subsequences as arguments. I think the doc should make this clearer. |
New changeset 0b9fe17 by Berker Peksag (Zackery Spytz) in branch '2.7': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: