sourcery icon indicating copy to clipboard operation
sourcery copied to clipboard

Invalid suggestion from Sourcery on set comprehension inside f-string

Open williamjamir opened this issue 2 years ago • 2 comments

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. image

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

williamjamir avatar Jun 24 '23 22:06 williamjamir

Thanks for raising - definitely an issue

Hellebore avatar Jun 26 '23 08:06 Hellebore

@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'}"

ruancomelli avatar Jun 26 '23 13:06 ruancomelli