This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: str.partition() is broken in 3.4
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: benjamin.peterson, ezio.melotti, georg.brandl, lemburg, pitrou, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2015-03-29 07:02 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
str_partition_kind.patch serhiy.storchaka, 2015-03-29 07:30
str_partition_kind_2.patch serhiy.storchaka, 2015-03-29 11:18
Messages (7)
msg239475 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-03-29 07:02
Tests added in b923eeaf8162 exposed a bug in str.partition() and str.rpartition() in 3.4 on big-endian platforms. It should exist in 3.3 too. It likely was fixed in 3.5 in issue23573.

http://buildbot.python.org/all/builders/PPC64%20PowerLinux%203.4/builds/913/steps/test/logs/stdio
======================================================================
FAIL: test_partition (test.test_unicode.UnicodeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.4.edelsohn-powerlinux-ppc64/build/Lib/test/test_unicode.py", line 383, in test_partition
    left + right, 'partition', delim)
  File "/home/shager/cpython-buildarea/3.4.edelsohn-powerlinux-ppc64/build/Lib/test/string_tests.py", line 63, in checkequal
    realresult
AssertionError: Tuples differ: ('bbbbbbbbbaaaaaaaaa', '', '') != ('', '𐌂', '\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00')

First differing element 0:
bbbbbbbbbaaaaaaaaa


- ('bbbbbbbbbaaaaaaaaa', '', '')
+ ('', '𐌂', '\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00')

======================================================================
FAIL: test_rpartition (test.test_unicode.UnicodeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.4.edelsohn-powerlinux-ppc64/build/Lib/test/test_unicode.py", line 399, in test_rpartition
    left + right, 'rpartition', delim)
  File "/home/shager/cpython-buildarea/3.4.edelsohn-powerlinux-ppc64/build/Lib/test/string_tests.py", line 63, in checkequal
    realresult
AssertionError: Tuples differ: ('', '', 'bbbbbbbbbaaaaaaaaa') != ('\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00', '𐌂', '')

First differing element 0:

bbbb

- ('', '', 'bbbbbbbbbaaaaaaaaa')
+ ('\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00', '𐌂', '')

----------------------------------------------------------------------

'bbbbbbbbbaaaaaaaaa'.partition('\U00010302') returns ('', '𐌂', '\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00')
'bbbbbbbbbaaaaaaaaa'.rpartition('\U00010302') returns ('\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00\x00\x00b\x00', '𐌂', '')
msg239476 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-03-29 07:30
Here is a patch that should fix the bug.

Can it be committed in 3.3 Georg? The patch is simple and fixes a bug in basic type.
msg239477 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-03-29 07:36
The bug can be reproduced on little-endian platform.

>>> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.partition('Ā')
('A', 'Ā', 'B\x00C\x00D\x00E\x00F\x00G\x00H\x00I\x00J\x00K\x00L\x00M\x00')
>>> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.rpartition('Ā')
('A\x00B\x00C\x00D\x00E\x00F\x00G\x00H\x00I\x00J\x00K\x00L\x00M', 'Ā', '')
msg239479 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-03-29 07:52
The patch lacks unit test. You showed a test which fails also on little
endian.
msg239486 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-03-29 11:18
Added tests that fail on little and big endianess.
msg239492 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2015-03-29 14:53
lgtm
msg239496 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-03-29 16:24
New changeset c23713af8be7 by Serhiy Storchaka in branch '3.4':
Issue #23803: Fixed str.partition() and str.rpartition() when a separator
https://hg.python.org/cpython/rev/c23713af8be7

New changeset c48637f57e2b by Serhiy Storchaka in branch 'default':
Added explicit tests for issue #23803.
https://hg.python.org/cpython/rev/c48637f57e2b
History
Date User Action Args
2022-04-11 14:58:14adminsetgithub: 67991
2015-04-02 12:42:55serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-03-29 16:24:21python-devsetnosy: + python-dev
messages: + msg239496
2015-03-29 14:53:27benjamin.petersonsetmessages: + msg239492
2015-03-29 11:18:09serhiy.storchakasetfiles: + str_partition_kind_2.patch

messages: + msg239486
2015-03-29 07:52:49vstinnersetmessages: + msg239479
2015-03-29 07:36:53serhiy.storchakasetmessages: + msg239477
2015-03-29 07:31:00serhiy.storchakasetfiles: + str_partition_kind.patch

nosy: + georg.brandl
messages: + msg239476

keywords: + patch
stage: needs patch -> patch review
2015-03-29 07:02:47serhiy.storchakacreate