sourcery-ai / sourcery

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

refactor use-any can break existing code #191

Closed lonico closed 2 years ago

lonico commented 2 years ago

Issue description or question

-        self.ontap_version['valid'] = True
-        for key in self.ontap_version:
-            if self.ontap_version[key] == -1:
-                self.ontap_version['valid'] = False
-                break
+        self.ontap_version['valid'] = all(
+            self.ontap_version[key] != -1 for key in self.ontap_version
+        )

(variable) ontap_version: dict[str, str | int]

Sourcery - Use any() instead of for loop, Invert any/all to simplify comparisons sourcery(refactoring)

The proposed change fails when self.ontap_version['valid'] == -1.

(I agree the existing code is icky. A value of None or False would have been better.)

Sourcery Version

v0.10.2

Code editor or IDE name and version

vscode

OS name and version

Alpine 3.14.0.1 in WSL using VSCode on Windows

Hellebore commented 2 years ago

Thanks for raising! I don't quite understand the difference in behaviour - could you give a few more details?

ruancomelli commented 2 years ago

@lonico we were able to reproduce this. We'll release a fix for it as soon as possible.

ruancomelli commented 2 years ago

@lonico we implemented a fix for this bug. It will be available in the next nightly release and in v0.10.3. Thanks for reporting this issue!

Hellebore commented 2 years ago

Now released in 0.10.3.