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

Avoid curly brace escape in f-string format spec #7780

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Oct 3, 2023

Summary

This PR fixes a bug in the lexer for f-string format spec where it would consider the {{ (double curly braces) as an escape pattern.

This is not the case as evident by the PEP as well but I missed the part:

[..]

  • If in “format specifier mode” (see step 3), an opening brace ({) or a closing brace (}).
  • If not in “format specifier mode” (see step 3), an opening brace ({) or a closing brace (}) that is not immediately followed by another opening/closing brace.

Test Plan

Add a test case to verify the fix and update the snapshot.

fixes: #7778

@dhruvmanila
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@dhruvmanila dhruvmanila added the bug Something isn't working label Oct 3, 2023
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 3, 2023

CodSpeed Performance Report

Merging #7780 will improve performances by 2.94%

Comparing dhruv/no-double-curly-escape-in-format-spec (6d6c8e1) with main (c040fac)

Summary

⚡ 1 improvements
✅ 24 untouched benchmarks

Benchmarks breakdown

Benchmark main dhruv/no-double-curly-escape-in-format-spec Change
linter/default-rules[pydantic/types.py] 38.9 ms 37.8 ms +2.94%

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

@dhruvmanila dhruvmanila merged commit 69b8136 into main Oct 3, 2023
@dhruvmanila dhruvmanila deleted the dhruv/no-double-curly-escape-in-format-spec branch October 3, 2023 14:08
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

Successfully merging this pull request may close these issues.

False positive f-string SyntaxError
2 participants