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.

Title: restore python2 unicode literals in "ur" strings
Type: enhancement Stage:
Components: Unicode Versions: Python 3.3
Status: closed Resolution: wont fix
Dependencies: Superseder: Drop support for the "ur" string prefix
View: 15096
Assigned To: Nosy List: aronacher, christian.heimes, eric.araujo, ezio.melotti, rurpy2, vinay.sajip
Priority: normal Keywords:

Created on 2012-05-31 22:05 by rurpy2, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg162025 - (view) Author: rurpy (rurpy2) Date: 2012-05-31 22:05
PEP 414 proposes restoring the "u" string prefix (semantically as a "noop") to make porting from Python2 easier.  I would like to propose that "ru"-strings also interpret embedded "\uxxxx" unicode literals in the python2 fashion (as a single unicode character) rather than in the python 3.2 fashion (as 6 characters).

Many Python2 programs use unicode literals in strings because they can be represented and displayed in source code with the ascii character set.  For example, I often write ur" \u3000\u3042\t" rather than ur"  あ    " because the former is much clearer in source code than the latter and does not require the viewer to have a Japanese font installed.

However such a string must be manually converted for Python3 because the former string has a very different meaning in Python3 than Python2.  The equivalent in Python3 is " \u3000\u3042\\t".  AFAIK, 2to3 does not fix this.  Because there are no longer unicode literals in Python3 raw strings, any string with a unicode literal *has* to be a non-raw string (AFAICT).  This means that strings used as regexes, that have a lot of backslashes and have unicode literals, must have the backslashes doubled.  Doubling the backslashes in the above example is trivial but it is not trival in more realistic regexes.  This was one of the main reasons for having raw strings in Python2 I thought.  It is unfortunate that one looses this ability (in the presence of unicode literals) in Python3.

When I raised this issue on the Python user's list [*1], Terry Reedy made the suggestion that since the "u" string prefix was being reintroduced for python 3.3, that having the prefix also restore the python2 unicode literal handling would not introduce any incompatibilties and would greatly increase the ease of porting to Python3 for some programs.[*2]  He subsequently raised the issue on the dev list.[*3]

An argument might be made that this is an extra feature that would encourage the use of the "u"-prefix beyond that of easing porting from Python2.  Perhaps so but there is currently a hole in Python's capability that is difficult to work around, and I've seen no other proposals to fix it.  So it seems to me that the benefits of this proposal greatly outweigh that somewhat purist argument.
msg162051 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-06-01 05:38
See issue3665.
msg163045 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2012-06-17 09:33
See also
msg163286 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2012-06-20 15:29
Given the resolution of #15096, ISTM this will be a "wontfix", though I'll stop short of marking it as such myself.
msg165744 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-07-18 06:17
Should it be closed?
msg166834 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012-07-29 23:08
As of #15096 I've closed this bug as "won't fix".
Date User Action Args
2022-04-11 14:57:31adminsetgithub: 59178
2012-07-29 23:08:00christian.heimessetstatus: open -> closed

nosy: + christian.heimes
messages: + msg166834

resolution: wont fix
2012-07-28 08:57:04serhiy.storchakasetnosy: - serhiy.storchaka
2012-07-18 06:17:46serhiy.storchakasetmessages: + msg165744
2012-06-20 15:30:37vinay.sajipsetmessages: - msg163288
2012-06-20 15:30:11vinay.sajipsetmessages: + msg163288
2012-06-20 15:29:55vinay.sajipsetmessages: + msg163286
2012-06-19 16:19:25vinay.sajipsetsuperseder: Drop support for the "ur" string prefix
2012-06-17 09:33:35vinay.sajipsetnosy: + aronacher, vinay.sajip
messages: + msg163045
2012-06-01 18:04:15eric.araujosetnosy: + eric.araujo
2012-06-01 05:38:08serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg162051
title: restore python2 unicode literals in "ru" strings -> restore python2 unicode literals in "ur" strings
2012-05-31 22:05:13rurpy2create