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

Parse error on star expressions in f-strings #387

Closed
zsol opened this issue Sep 9, 2020 · 4 comments
Closed

Parse error on star expressions in f-strings #387

zsol opened this issue Sep 9, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@zsol
Copy link
Member

zsol commented Sep 9, 2020

❯ cat test.py
x = [1, 2]
print(f"List of: {*x,}")
❯ python3 test.py
List of: (1, 2)
❯ libcst print test.py
Traceback (most recent call last):
  File "python3.7/site-packages/fbcode/libcst/_parser/base_parser.py", line 152, in _add_token
    plan = stack[-1].dfa.transitions[transition]
KeyError: ReservedString(*)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "python3.7/site-packages/fbcode/libcst/tool.py", line 832, in <module>
    main(os.environ.get("LIBCST_TOOL_COMMAND_NAME", "libcst.tool"), sys.argv[1:])
  File "python3.7/site-packages/fbcode/libcst/tool.py", line 827, in main
    return lookup.get(args.action or None, _invalid_command)(proc_name, command_args)
  File "python3.7/site-packages/fbcode/libcst/tool.py", line 277, in _print_tree_impl
    else PartialParserConfig()
  File "python3.7/site-packages/fbcode/libcst/_parser/entrypoints.py", line 76, in parse_module
    detect_default_newline=True,
  File "python3.7/site-packages/fbcode/libcst/_parser/entrypoints.py", line 51, in _parse
    result = parser.parse()
  File "python3.7/site-packages/fbcode/libcst/_parser/base_parser.py", line 111, in parse
    self._add_token(token)
  File "python3.7/site-packages/fbcode/libcst/_parser/base_parser.py", line 191, in _add_token
    raw_column=token.start_pos[1],
libcst._exceptions.ParserSyntaxError: Syntax Error @ 2:19.
Incomplete input. Unexpectedly encountered '*'.

print(f"List of: {*x,}")
                  ^
@zsol zsol added the bug Something isn't working label Sep 9, 2020
@jimmylai
Copy link
Contributor

Similar to the other missing comprehension parsing in f-string. This is caused by missing star_expr support in fstring_expr.

@taylorhughes
Copy link

Also seen with: f"\N{DOUBLE EXCLAMATION MARK} Foobar" -- a subset of the named emoji strings we have are causing this, guessing they are missing on this system's emoji set or something.

@thatch
Copy link
Contributor

thatch commented Nov 20, 2020

@taylorhughes your last comment about named escapes is davidhalter/parso#154 in parso.

@zsol I think the original bug is basically the same as #416 and the PR for that also fixed this one. taylor's still exists, do you want to close and file a new one to track an upstream fix?

@zsol
Copy link
Member Author

zsol commented Nov 20, 2020

There's #400 for the one @taylorhughes mentions. Let's close this. Thx for the fix!

@zsol zsol closed this as completed Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants