sourcery
sourcery copied to clipboard
Invalid suggestion from Sourcery on set comprehension inside f-string
Checklist
- [X] I have searched the Sourcery documentation for the issue and found nothing
- [X] I have checked there are no open bugs referencing the same bug or problem
Description
That is an invalid suggestion from Sourcery.
Code snippet that reproduces issue
>>> test = [1, None, {}, 3]
>>> f"Test - {set(i for i in test)}"
"Test - {'NoneType', 'int', 'dict'}"
# With the suggestion from Sourcery
>>> f"Test - {{type(i).__name__ for i in test}}"
'Test - {type(i).__name__ for i in test}'
Debug Information
IDE Version: PyCharm 2023.1.3 (Community Edition)
Sourcery Version: 1.4.0
Operating system and Version: Ubuntu 23.04
Thanks for raising - definitely an issue
@Hellebore adding an extra space between the surrounding braces fixes the issue:
>>> test = [1, None, {}, 3]
>>> f"Test - { {type(i).__name__ for i in test} }"
"Test - {'NoneType', 'int', 'dict'}"