Skip to content

Allow no whitespace after lambda body in certain cases#939

Merged
zsol merged 9 commits intomainfrom
pr939
Jun 7, 2023
Merged

Allow no whitespace after lambda body in certain cases#939
zsol merged 9 commits intomainfrom
pr939

Conversation

zsol added 9 commits May 27, 2023 10:07
For an expression like `f"{one:{two:}{three}}"`, `three` is not in an f-string spec, and should be tokenized accordingly.

This PR fixes the `format_spec_count` bookkeeping in the tokenizer, so it properly decrements it when a closing `}` is encountered but only if the `}` closes a format_spec.

Reported in #930.
This is an obscure one.

`_ if 0else _` failed to parse with some very weird errors. It turns out that the tokenizer tries to parse `0else` as a single number, but when it encounters `l` it realizes it can't be a single number and it backtracks.

Unfortunately the backtracking logic was broken, and it failed to correctly backtrack one of the offsets used for whitespace parsing (the byte offset since the start of the line). This caused whitespace nodes to refer to incorrect parts of the input text, eventually resulting in the above behavior.

This PR fixes the bookkeeping when the tokenizer backtracks.

Reported in #930.
Python accepts code where `lambda` follows a `*`, so this PR relaxes validation rules for Lambdas.

Raised in #930.
This PR relaxes the accepted types for the `elt` field in `ListComp`, `SetComp`, and `GenExp`, as well as the `key` and `value` fields in `DictComp`.

Fixes #500.
For example in `_ if _ else""if _ else _`.

Raised in #930. Also fixes #854.
Like in `[_:=''for _ in _]`

Raised in #930.
Like in `[lambda:()for _ in _]`

Reported in #930.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 28, 2023

Codecov Report

❌ Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.92%. Comparing base (59aeceb) to head (ea4ea34).
⚠️ Report is 246 commits behind head on main.

Files with missing lines Patch % Lines
libcst/_nodes/expression.py 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #939      +/-   ##
==========================================
- Coverage   90.92%   90.92%   -0.01%     
==========================================
  Files         254      254              
  Lines       25937    25955      +18     
==========================================
+ Hits        23584    23600      +16     
- Misses       2353     2355       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants