Skip to content
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

\u and \U in raw strings have regressed in 3.0a4 #46809

Closed
gvanrossum opened this issue Apr 5, 2008 · 4 comments
Closed

\u and \U in raw strings have regressed in 3.0a4 #46809

gvanrossum opened this issue Apr 5, 2008 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error

Comments

@gvanrossum
Copy link
Member

BPO 2557
Nosy @malemburg, @gvanrossum, @benjaminp

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:

assignee = None
closed_at = <Date 2008-04-05.14:55:15.299>
created_at = <Date 2008-04-05.14:45:35.562>
labels = ['interpreter-core', 'type-bug', 'release-blocker']
title = '\\u and \\U in raw strings have regressed in 3.0a4'
updated_at = <Date 2008-04-07.18:07:50.187>
user = 'https://github.com/gvanrossum'

bugs.python.org fields:

activity = <Date 2008-04-07.18:07:50.187>
actor = 'gvanrossum'
assignee = 'none'
closed = True
closed_date = <Date 2008-04-05.14:55:15.299>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2008-04-05.14:45:35.562>
creator = 'gvanrossum'
dependencies = []
files = []
hgrepos = []
issue_num = 2557
keywords = []
message_count = 4.0
messages = ['64977', '64979', '64987', '65087']
nosy_count = 3.0
nosy_names = ['lemburg', 'gvanrossum', 'benjamin.peterson']
pr_nums = []
priority = 'release blocker'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue2557'
versions = ['Python 3.0']

@gvanrossum
Copy link
Member Author

In 2.x, \uDDDD and \UDDDDDDDD are interpreted as Unicode escapes in
raw Unicode strings. That was a mistake, but we can't fix it (except
when using "from __future__ import unicode_literals"). In 3.0, \u or
\U in a raw string should have no special meaning -- it's just a
backslash followed by 'u' or 'U'.

This was fixed in 3.0a3. It seems to have reverted to the old (2.x)
behavior in 3.0a4.

THIS MUST BE FIXED!

@gvanrossum gvanrossum added release-blocker type-bug An unexpected behavior, bug, or error labels Apr 5, 2008
@gvanrossum gvanrossum changed the title \u and \U in raw strings have reverted \u and \U in raw strings have regressed in 3.0a4 Apr 5, 2008
@gvanrossum gvanrossum added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 5, 2008
@benjaminp
Copy link
Contributor

fixed in r62165.

@malemburg
Copy link
Member

The was not a mistake, it was done on purpose since there would
otherwise have been no way to add non-ASCII Unicode code points to a raw
Unicode literal, rendering raw Unicode literals pretty useless.

Even if you use UTF-8 as source code encoding, there's no way to add
half a surrogate to a raw Unicode literal without the Unicode literals.

If you need to write a Unicode literal escape using the raw Unicode
escape encoding, you can use '\x1234'.

@gvanrossum
Copy link
Member Author

We went over this before. *I* consider the 2.x behavior a mistake, and
a decision was made to change in 3.0. It got much worse in 3.0 because
all literals are Unicode (except byte literals).

To add a unicode value to a raw string, just concatenate a raw string
and a non-raw string, e.g.

r'whatever' '\u1234' r'whatever'

I don't understand what you meant by '\x1234' -- the \x escape only
accepts 2 hex digits.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants