Instagram / Instagram/LibCST

`ParserSyntaxError` on `from foo import (bar \n as baz)`

Open
#530 4 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

```python
import libcst as cst

code = """
from math import (nan
as NaN)
"""
compile(code, "", "exec") # (no error)

cst.parse_module(code) # ParserSyntaxError: Syntax Error @ 4:9.
# Internal error: There must be at least one space before 'as'.
```

While this is really weird code, it does actually happen in the wild, e.g. [here](https://bitbucket.org/mrabarnett/mrab-regex/src/d81009be6985efda7a533d767901f6ba192b7b71/regex_3/regex.py#lines-428:429) in the [`regex` package](https://pypi.org/project/regex/).

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.