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

Support named unicode characters in f-strings #160

Merged
merged 2 commits into from
Nov 22, 2020

Commits on Nov 21, 2020

  1. Support named unicode characters in f-strings

    Fixes davidhalter#154
    
    The previous behavior misinterpreted the curly braces as enclosing an
    expression.  This change does some cursory validation so we can still
    get parse errors in the most egregious cases, but does not validate that
    the names are actually valid, only that they are name-shaped and have a
    chance of being valid.
    
    The character names appear to obey a few rules:
    * Case insensitive
    * Name characters are `[A-Z0-9 \-]`
    * Whitespace before or after is not allowed
    * Whitespace in the middle may only be a single space between words
    * Dashes may occur at the start or middle of a word
    
    ```py
    f"\N{A B}"           # might be legal
    f"\N{a b}"           # equivalent to above
    f"\N{A     B}"       # no way
    f"\N{    A B     }"  # no way
    f"""\N{A
    B}"""                # no way
    ```
    
    For confirming this regex matches all (current) unicode character names:
    
    ```py
    import re
    import sys
    import unicodedata
    
    R = re.compile(r"[A-Za-z0-9\-]+(?: [A-Za-z0-9\-]+)*")
    
    for i in range(sys.maxunicode):
        try:
            name = unicodedata.name(chr(i))
        except ValueError:
            # Some small values like 0 and 1 have no name, /shrug
            continue
        m = R.fullmatch(name)
        if m is None:
            print("FAIL", repr(name))
    ```
    thatch committed Nov 21, 2020
    Configuration menu
    Copy the full SHA
    d42bc31 View commit details
    Browse the repository at this point in the history

Commits on Nov 22, 2020

  1. Configuration menu
    Copy the full SHA
    ed7f35a View commit details
    Browse the repository at this point in the history