The Wayback Machine - https://web.archive.org/web/20250604063710/https://github.com/RustPython/RustPython/issues/3511
Skip to content

CPython does not support some emojis as variable name while RustPython does #3511

Open
@chengongpp

Description

@chengongpp

Feature

on CPython 3.10:

$ python
Python 3.10.1 (main, Dec 18 2021, 23:53:45) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 🦀 = 0
  File "<stdin>", line 1
    🦀 = 0
    ^
SyntaxError: invalid character '🦀' (U+1F980)

on RustPython 0.1.2:

$ ./rustpython
Welcome to the magnificent Rust Python 0.1.2 interpreter 😱 🖖
>>>>> 🦀 = 0
>>>>> 🦀
0

According to python doc, valid identifiers are defined as:

identifier   ::=  xid_start xid_continue*
id_start     ::=  <all characters in general categories Lu, Ll, Lt, Lm, Lo, Nl, the underscore, and characters with the Other_ID_Start property>
id_continue  ::=  <all characters in id_start, plus characters in the categories Mn, Mc, Nd, Pc and others with the Other_ID_Continue property>
xid_start    ::=  <all characters in id_start whose NFKC normalization is in "id_start xid_continue*">
xid_continue ::=  <all characters in id_continue whose NFKC normalization is in "id_continue*">

The Unicode category codes mentioned above stand for:
Lu - uppercase letters
Ll - lowercase letters
Lt - titlecase letters
Lm - modifier letters
Lo - other letters
Nl - letter numbers
Mn - nonspacing marks
Mc - spacing combining marks
Nd - decimal numbers
Pc - connector punctuations
Other_ID_Start - explicit list of characters in PropList.txt to support backwards compatibility
Other_ID_Continue - likewise

While Ferris-chan 🦀 (U+1F980) is not included above, it should probably not be considered a valid variable name?

Python Documentation

Lexical Analysis: Identifiers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions