sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.5k stars 65 forks source link

Invalid suggestion from Sourcery on set comprehension inside f-string #362

Open williamjamir opened 1 year ago

williamjamir commented 1 year ago

Checklist

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

Hellebore commented 1 year ago

Thanks for raising - definitely an issue

ruancomelli commented 1 year ago

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