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

Unicode control characters are not allowed as identifiers #49608

Closed
baijum mannequin opened this issue Feb 24, 2009 · 7 comments
Closed

Unicode control characters are not allowed as identifiers #49608

baijum mannequin opened this issue Feb 24, 2009 · 7 comments
Labels
topic-unicode type-bug An unexpected behavior, bug, or error

Comments

@baijum
Copy link
Mannequin

baijum mannequin commented Feb 24, 2009

BPO 5358
Nosy @loewis, @ezio-melotti
Files
  • identifier.py: File with Unicode control character in identifier
  • 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 2009-02-27.18:32:17.612>
    created_at = <Date 2009-02-24.11:53:50.445>
    labels = ['type-bug', 'expert-unicode']
    title = 'Unicode control characters are not allowed as identifiers'
    updated_at = <Date 2009-02-27.18:32:17.537>
    user = 'https://bugs.python.org/baijum'

    bugs.python.org fields:

    activity = <Date 2009-02-27.18:32:17.537>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-02-27.18:32:17.612>
    closer = 'loewis'
    components = ['Unicode']
    creation = <Date 2009-02-24.11:53:50.445>
    creator = 'baijum'
    dependencies = []
    files = ['13162']
    hgrepos = []
    issue_num = 5358
    keywords = []
    message_count = 7.0
    messages = ['82664', '82666', '82820', '82821', '82822', '82842', '82858']
    nosy_count = 4.0
    nosy_names = ['loewis', 'ezio.melotti', 'mrabarnett', 'baijum']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5358'
    versions = ['Python 3.0', 'Python 3.1']

    @baijum
    Copy link
    Mannequin Author

    baijum mannequin commented Feb 24, 2009

    I tried to use Zero-width joiner (U+200D) as part of an identifier.
    It produce an exception like this:

    SyntaxError: invalid character in identifier

    I have attached the Python file which produce this error.

    Zero-width joiner (U+200D) is a Unicode control character:
    http://en.wikipedia.org/wiki/Unicode_control_characters

    @baijum baijum mannequin added topic-unicode type-bug An unexpected behavior, bug, or error labels Feb 24, 2009
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Feb 24, 2009

    Why do you think this is a bug?

    @baijum
    Copy link
    Mannequin Author

    baijum mannequin commented Feb 27, 2009

    On a further look at this issue, I understood Python cannot use all
    Unicode control characters as identifiers. But for many international
    languages, without some control characters like ZWJ & ZWNJ [1], it won't
    be possible to construct all characters with proper visual
    representation. So, if Python really want to support international
    characters as identifiers (for some reason), ZWJ & ZWNJ are unavoidable,
    may be some other characters also.

    [1] http://en.wikipedia.org/wiki/Zero-width_joiner
    http://en.wikipedia.org/wiki/Zero-width_non-joiner

    @baijum
    Copy link
    Mannequin Author

    baijum mannequin commented Feb 27, 2009

    I think RFC-3454 [1] can be used as a base for selecting the control
    characters which can be used as a valid identifier character.

    [1] http://www.rfc-editor.org/rfc/rfc3454.txt

    @ezio-melotti
    Copy link
    Member

    Valid identifiers should begin with a letter or '_' and contain only
    letters, numbers and '_'. This probably means that only the Unicode
    characters that belong to the categories Ll, Lu (Letter Lower/Upper
    case), Nd (Number, Decimal Digit) and Pc (Punctuation, Connector) - and
    possibly other categories like Lm, Lt, No and Nl - are valid.

    Some examples:
    >>> a-b = 5 # U+FF0D, Cat: Pd, FULLWIDTH HYPHEN-MINUS
    SyntaxError: invalid character in identifier
    >>> a# = 5 # U+FF03, Cat: Po, FULLWIDTH NUMBER SIGN
    SyntaxError: invalid character in identifier
    >>> a)b = 5 # U+FF09, Cat: Pe, FULLWIDTH RIGHT PARENTHESIS
    SyntaxError: invalid character in identifier
    >>> a_b = 5 # U+FF3F, Cat: Pc, FULLWIDTH LOW LINE
    >>> a_b
    5
    >>> a﹍b﹎c﹏d = 5 # U+FE4D, U+FE4E, U+FE4F, Cat: Pc
    >>> a﹍b﹎c﹏d
    5

    @mrabarnett
    Copy link
    Mannequin

    mrabarnett mannequin commented Feb 27, 2009

    The definition of a word in the new re module (actually targetted at
    Python 2.7) is currently a sequence of L&, N&, M& and Pc.

    I suppose ideally we want the definitions of a word and an identifier to
    be basically the same, except that an identifier can't start with N&.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Feb 27, 2009

    See PEP-3131 for a specification what is an identifier in Python.

    Closing this as "won't fix".

    @loewis loewis mannequin closed this as completed Feb 27, 2009
    @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
    topic-unicode type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant