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: Attempt to format ascii and non-ascii strings together fails with "... UCS2 ..."
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, ddvoinikov, loewis, python-dev, r.david.murray, vstinner
Priority: normal Keywords: easy, patch

Created on 2012-04-23 13:18 by ddvoinikov, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
format_nonascii.patch vstinner, 2012-04-23 21:16 review
Messages (10)
msg159014 - (view) Author: Dmitry Dvoinikov (ddvoinikov) Date: 2012-04-23 13:18
Using Python 3.3.0a2 (default, Apr  1 2012, 19:34:58) [MSC v.1500 64 bit (AMD64)] on win32.

This line of code

"{0:s}{1:s}".format("ABC", "\u0410\u0411\u0412")

results in

SystemError: Cannot copy UCS2 characters into a string of ascii characters
msg159015 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-23 13:45
I get this result on a debug build of default on linux:

>>> "{0:s}{1:s}".format("ABC", "\u0410\u0411\u0412")
python: Objects/unicodeobject.c:1223: _copy_characters: Assertion `ch <= to_maxchar' failed.
msg159023 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-04-23 14:55
New changeset c7163a7f7cd2 by Benjamin Peterson in branch 'default':
inherit maxchar of field value where needed (closes #14648)
http://hg.python.org/cpython/rev/c7163a7f7cd2
msg159024 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-23 14:59
A test needs to be added for this.
msg159025 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-04-23 15:04
What makes you think there isn't one?
msg159026 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-23 15:22
> New changeset c7163a7f7cd2 by Benjamin Peterson in branch 'default':
> inherit maxchar of field value where needed (closes #14648)
> http://hg.python.org/cpython/rev/c7163a7f7cd2

The patch is wrong if the format only gets a substring instead of the
full string. I have a pending patch for this.
msg159027 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-04-23 15:23
Ah, you are right.
msg159033 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-23 15:47
> What makes you think there isn't one?

Poor eyesight?  Sorry.
msg159083 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-23 21:16
>>>> "{0:s}{1:s}".format("ABC", "\u0410\u0411\u0412")
> python: Objects/unicodeobject.c:1223: _copy_characters: Assertion `ch <= to_maxchar' failed.

Attached patch fixes this issue.
msg159087 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-04-23 21:43
New changeset 139c3ae84772 by Victor Stinner in branch 'default':
Close #14648: Compute correctly maxchar in str.format() for substrin
http://hg.python.org/cpython/rev/139c3ae84772
History
Date User Action Args
2022-04-11 14:57:29adminsetgithub: 58853
2012-04-23 21:43:12python-devsetstatus: open -> closed
resolution: fixed
messages: + msg159087

stage: test needed -> resolved
2012-04-23 21:16:07vstinnersetfiles: + format_nonascii.patch
keywords: + patch
messages: + msg159083
2012-04-23 15:47:14r.david.murraysetmessages: + msg159033
2012-04-23 15:40:57benjamin.petersonsetstatus: closed -> open
resolution: fixed -> (no value)
2012-04-23 15:23:19benjamin.petersonsetmessages: + msg159027
2012-04-23 15:22:19vstinnersetmessages: + msg159026
2012-04-23 15:04:09benjamin.petersonsetstatus: open -> closed
nosy: + benjamin.peterson
messages: + msg159025

2012-04-23 14:59:55r.david.murraysetstatus: closed -> open
priority: release blocker -> normal
messages: + msg159024

keywords: + easy
stage: resolved -> test needed
2012-04-23 14:55:36python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg159023

resolution: fixed
stage: needs patch -> resolved
2012-04-23 13:45:08r.david.murraysetpriority: normal -> release blocker

nosy: + loewis, vstinner, r.david.murray
messages: + msg159015

type: behavior -> crash
stage: needs patch
2012-04-23 13:18:06ddvoinikovcreate