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

[Python] whitespace around = formatter in f-strings #3216

Closed
sweettyler opened this issue Jan 27, 2022 · 6 comments · Fixed by #3218
Closed

[Python] whitespace around = formatter in f-strings #3216

sweettyler opened this issue Jan 27, 2022 · 6 comments · Fixed by #3218
Labels
T: bug A bug in an existing language feature

Comments

@sweettyler
Copy link

What happened?

I tried some new features introduced in Python 3.8, and happened to find that, in the example (attached screenshot), the "=" are highlighted differently, depending on if there is a blank behind it.

_print_f_string

Guess there is something wrong.

In VS code "=" has the same color in both print.

_print_f_string_vscode

@sweettyler sweettyler added the T: bug A bug in an existing language feature label Jan 27, 2022
@jfcherng
Copy link
Collaborator

Wow! I didn't even know this = feature. Save some typing when debugging using print.

>>> a = 5
>>> print(f"{a = }")
a = 5

That = behaves more like a format modifier?

@sweettyler
Copy link
Author

@jfcherng you may find some more info: https://bugs.python.org/issue36817. There are also some official docs.

@michaelblyons michaelblyons changed the title [Python] Incorrect highlighting [Python] = formatter in f-strings Jan 27, 2022
@FichteFoll
Copy link
Collaborator

FichteFoll commented Jan 27, 2022

Initially implemented in #2006. I just did some quick testing and it appears that only whitespace (space, tab and even newline in block strings) is allowed and preserved here. Any token before = would result in a syntax error and any other unexpected token after it throws an error as well because } is expected (or ! or :). That should make it fairly trivial to support.

Note that the embedded source scope should then not cover the whitespace that will be preserved because that will be part of the final string literally.

@FichteFoll FichteFoll changed the title [Python] = formatter in f-strings [Python] whitespace around = formatter in f-strings Jan 27, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Jan 27, 2022
Fixes: sublimehq#3216

This commit ...

1. uses multi-push to not push into python expression context twice.
   see: https://docs.python.org/3.6/reference/lexical_analysis.html#f-strings
2. adds requested support for surrounding whitespace of `=` debug
   modifier.
3. adds named contexts and re-uses common modifier patterns in both
   f-string contexts.
deathaxe added a commit that referenced this issue Jan 28, 2022
Fixes: #3216

This commit ...

1. uses multi-push to not push into python expression context twice.
   see: https://docs.python.org/3.6/reference/lexical_analysis.html#f-strings
2. adds requested support for surrounding whitespace of `=` debug
   modifier.
3. adds named contexts and re-uses common modifier patterns in both
   f-string contexts.
@sweettyler
Copy link
Author

@deathaxe I don't find anything change after I upgrade SUBL to version 4128.

@michaelblyons
Copy link
Collaborator

@sweettyler Syntax highlighting changes are not included in every ST release. The changelog will mention them if they are new. To apply the changes for now, you can follow the ReadMe instructions at the root of this repo or use something like OverrideAudit to change just the sublime-syntax file.

@sweettyler
Copy link
Author

@michaelblyons Thank you! I see now.

mitranim pushed a commit to mitranim/Packages that referenced this issue Mar 25, 2022
Fixes: sublimehq#3216

This commit ...

1. uses multi-push to not push into python expression context twice.
   see: https://docs.python.org/3.6/reference/lexical_analysis.html#f-strings
2. adds requested support for surrounding whitespace of `=` debug
   modifier.
3. adds named contexts and re-uses common modifier patterns in both
   f-string contexts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug A bug in an existing language feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants