You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
b=list(range(10))
print(f'{{a if a < 6 else 0 for a in b}}')
which is actually wrong if it's in a fstring since it actually just escapes the innermost curly brace. This results in the printing of {a if a < 6 else 0 for a in b}
@charliermarsh It's not a bad change in fstrings, and it is potentially more performant, just need to be careful to do it properly :P . Another option is just to add an extra space around the inserted braces unconditionally and let black or whatever formatter you use deal with it.
One annoying false positive change in this flake8-comprehensions are set/dict conversions to literals in f'strings.
which prints:
{0, 1, 2, 3, 4, 5}
becomes
which is actually wrong if it's in a fstring since it actually just escapes the innermost curly brace. This results in the printing of
{a if a < 6 else 0 for a in b}
It should fixit as
The space will prevent the curly brace from being escaped and is deleted when the fstring resolves which should provide identical behavior to the original code snippit. See this Stackoverflow post: https://stackoverflow.com/questions/49120113/dictionary-set-comprehensions-inside-of-f-string
I suspect you wound find similar behavior for C402 with dict comprehensions.
Command, Version Info, and Settings
The text was updated successfully, but these errors were encountered: