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

Python interreter and codecs module don't recognize unicode escape \u{xxx}. #129392

Open
mrolle45 opened this issue Jan 28, 2025 · 2 comments
Open
Labels
pending The issue will be closed if no feedback is provided

Comments

@mrolle45
Copy link

mrolle45 commented Jan 28, 2025

Bug report

Bug description:

>>> codecs.decode('\u{0041}',encoding='unicode-escape')
  File "<python-input-2>", line 1
    codecs.decode('\u{0041}',encoding='unicode-escape')
                  ^^^^^^^^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX escape
>>> codecs.decode('\u0041',encoding='unicode-escape')
'A'
>>> '\u{0041}'
  File "<python-input-4>", line 1
    '\u{0041}'
    ^^^^^^^^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX escape
>>> '\u0041'
'A'

I'm not sure when the \u{xxx} escape was introduced to the world, but it should be recognized by codecs.decode and the Python interpreter. The above sample was run on Python 3.13.1 on Windows.

CPython versions tested on:

3.13

Operating systems tested on:

No response

@mrolle45 mrolle45 added the type-bug An unexpected behavior, bug, or error label Jan 28, 2025
@terryjreedy terryjreedy added pending The issue will be closed if no feedback is provided and removed type-bug An unexpected behavior, bug, or error labels Jan 28, 2025
@terryjreedy
Copy link
Member

The codecs call is irrelevant. You entered an invalid string. You either need to omit the parentheses, as you later did, or use '\N{CHARNAME}', where 'CHARNAME' is a recognized name in the Unicode database. See https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences.

@ericvsmith
Copy link
Member

I agree this isn't a bug.

@mrolle45 : What's your evidence that this escape sequence was "introduced to the world"? And even if it were, we'd need more motivation than that to add it to Python. What problem would it solve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending The issue will be closed if no feedback is provided
Projects
None yet
Development

No branches or pull requests

3 participants