From fd2841f2cff546fc704cfd0bd5962918e951360b Mon Sep 17 00:00:00 2001 From: Yonathan Randolph Date: Wed, 11 Oct 2023 00:52:52 -0700 Subject: [PATCH] Revert "Fix transformation of non-iter dict methods in for loops" This reverts commit 8a1ef249bf6b75393df60cfcf9615eca915f592e. It is often incorrect to omit the list() when converting for x in d.items() to python3 because if you omit list(), then adding or removing elements while iterating will raise RuntimeError: dictionary changed size during iteration. --- modernize/fixes/fix_dict_six.py | 6 ------ tests/test_fix_dict_six.py | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/modernize/fixes/fix_dict_six.py b/modernize/fixes/fix_dict_six.py index 7de96cf..e5df914 100644 --- a/modernize/fixes/fix_dict_six.py +++ b/modernize/fixes/fix_dict_six.py @@ -43,9 +43,3 @@ def transform(self, node, results): return super().transform(node, results) else: return self.transform_iter(node, results) - - def in_special_context(self, node, isiter): - # Redefined from parent class to make "for x in d.items()" count as - # in special context; fissix only counts for loops as special context - # for the iter* methods. - return super().in_special_context(node, True) diff --git a/tests/test_fix_dict_six.py b/tests/test_fix_dict_six.py index 950941e..a248bec 100644 --- a/tests/test_fix_dict_six.py +++ b/tests/test_fix_dict_six.py @@ -38,11 +38,11 @@ DICT_IN_LOOP = ( """\ for k in x.items(): - pass + del x[k] """, """\ -for k in x.items(): - pass +for k in list(x.items()): + del x[k] """, )