Instagram / Instagram/LibCST

Rust parser: Error with parenthesised annotations

Open
#1,011 0 comments 0 reactions 0 assignees View on GitHub
bug parsing
Dominant language
Python
Stars
1.9k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

The following legal code errors on the Rust parser, but not the Python one:

```py
(n): int = 1
```

```console
$ python -m libcst.tool print tmp.py
```

```pytb
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "...\Lib\site-packages\libcst\tool.py", line 863, in
main(os.environ.get("LIBCST_TOOL_COMMAND_NAME", "libcst.tool"), sys.argv[1:])
File "...\Lib\site-packages\libcst\tool.py", line 858, in main
return lookup.get(args.action or None, _invalid_command)(proc_name, command_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "...\Lib\site-packages\libcst\tool.py", line 279, in _print_tree_impl
tree = parse_module(
^^^^^^^^^^^^^
File "...\Lib\site-packages\libcst\_parser\entrypoints.py", line 109, in parse_module
result = _parse(
^^^^^^^
File "...\Lib\site-packages\libcst\_parser\entrypoints.py", line 55, in _parse
return parse(source_str)
^^^^^^^^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
parser error: error at 1:5: expected one of !=, %, &, (, *, **, +, ,, -, ., /, //, ;, <, <<, <=, =, ==, >, >=, >>, @, NEWLINE, [, ^, and, if, in, is, not, or, |

(n): int = 1
^
```

LibCST version 1.0.1; Python 3.11.5; Windows

A

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.