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
I have checked there are no open bugs referencing the same bug or problem
Description
When defining a set attribute by using add in a loop, set-comprehension triggers even when there are conditionals involving the set being added to. The equivalent refactoring does not appear for defining variables. Here is some code sample:
class Symmetrizer:
def __init__(self, pairs):
self.unordered_pairs = set()
for x, y in pairs:
if (y, x) not in self.unordered_pairs:
self.unordered_pairs.add((x,y))
Symmetrizer({(1, 2), (3, 4), (2, 1)})
The suggested refactoring is to replace the __init__ body by:
self.unordered_pairs = {(x, y) for x, y in pairs if (y, x) not in self.unordered_pairs}
which raises an AttributeError.
Debug Information
IDE Version:
PyCharm Professional Edition 2022.2.1
Sourcery Version:
Sourcery 0.12.7
Operating system and Version:
Linux, Fedora 36
The text was updated successfully, but these errors were encountered:
Checklist
Description
When defining a
set
attribute by usingadd
in a loop,set-comprehension
triggers even when there are conditionals involving the set being added to. The equivalent refactoring does not appear for defining variables. Here is some code sample:The suggested refactoring is to replace the
__init__
body by:which raises an
AttributeError
.Debug Information
IDE Version:
PyCharm Professional Edition 2022.2.1
Sourcery Version:
Sourcery 0.12.7
Operating system and Version:
Linux, Fedora 36
The text was updated successfully, but these errors were encountered: