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

Ignore code inside Python f-strings #599

Open
5TuX opened this issue Jan 30, 2025 · 1 comment
Open

Ignore code inside Python f-strings #599

5TuX opened this issue Jan 30, 2025 · 1 comment

Comments

@5TuX
Copy link

5TuX commented Jan 30, 2025

Currently, Spell Right does not provide a way to ignore only the code inside {} in Python f-strings while still spell-checking the surrounding text. This is an issue because variables and function calls inside {} often trigger spelling errors.

In this example, we expect len(data) not to be underlined, but "potatos" should be:

my_string = f"There are {len(data)} potatos in the dataset"
my_dict = {
    "potatos": 1,
    "tomatoes": 2,
}

Spell Right currently does not handle this as desired: "potatos" is properly underlined, but the len function call is also underlined when it should not.

A workaround using ignoreRegExpsByClass can ignore entire f-strings, but it does not allow selectively ignoring only the interpolated expressions inside {}, so ignoring entire f-strings results in missed typos in the surrounding text.

"spellright.ignoreRegExpsByClass": {
    "python": [
        "/f[\"'].*?{(.*)}.*[\"']/g",
    ]
}

With this workaround, "len" is not underlined, but the first "potatos" error is missed as it is part of the f-sting which is entirely ignored.

Feature Request:

  • Add an option to ignore only the code inside {} in f-strings (e.g., function calls, variables) while still spell-checking the surrounding text.
  • Or, improve regex handling so that capturing parentheses can be used in ignoreRegExpsByClass to ignore specific parts of f-strings without skipping the entire f-string content.

Would this be possible to implement? Thank you for the great extension !

@5TuX
Copy link
Author

5TuX commented Jan 30, 2025

This issue has also been reported in #298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant