Instagram / Instagram/LibCST

AnnAssign allows invalid whitespace around equals

Open
#488 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

I noticed that `AnnAssign` allows for whitespace which includes newlines before or after the equals without a line continuation character. Is this expected? It seems when you construct other nodes, they throw a `CSTValidationError` if the node would represent invalid Python code.

Here is an example where there is a newline before the equals sign:
```Python3
from libcst import (AnnAssign, Annotation, AssignEqual, Name,
ParenthesizedWhitespace, TrailingWhitespace)

AnnAssign(
target=Name(
value='foo',
),
annotation=Annotation(
annotation=Name(
value='Foo'
),
),
value=Name(
value='bar'
),
equal=AssignEqual(
whitespace_before=ParenthesizedWhitespace(
first_line=TrailingWhitespace()
),
)
)

```

And this would represent the following:
```Python3
foo:Foo
=bar
```

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.