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
class ValuesDict:
"""Dict-like container that iterates over the values."""
def __init__(self, value):
self.value = value
def __iter__(self):
yield from self.values()
def keys(self):
return self.value.keys()
def values(self):
return self.value.values()
d = {"a": 1, "b": 2, "c": 3}
vd = ValuesDict(d)
for key in vd.keys():
print(key)
This is the original expected output:
$ python row.py
a
b
c
Applying fixes for SIM118:
$ ruff --select=SIM118 --fix row.py
Found 1 error(s) (1 fixed, 0 remaining).
$ git diff
diff --git a/row.py b/row.py
index 1e7536d..7751a3b 100644
--- a/row.py
+++ b/row.py
@@ -18,5 +18,5 @@ class ValuesDict:
d = {"a": 1, "b": 2, "c": 3}
vd = ValuesDict(d)
-for key in vd.keys():
+for key in vd:
print(key)
This changes the code behavior:
$ python row.py
1
2
3
The text was updated successfully, but these errors were encountered:
Yes I think we currently have many lints that assume a conventional implementation of some __dunder__ methods. I agree that we should categorize the applicability of such rules, I just opened #1997 for that :)
Yeah this is probably impossible to avoid completely right now. But we should categorize fixes as described in the issue and consider requiring opt-in for those that could be "dangerous".
Example code:
This is the original expected output:
Applying fixes for SIM118:
This changes the code behavior:
The text was updated successfully, but these errors were encountered: