]> granicus.if.org Git - python/commitdiff
bpo-29957: change LBYL key lookup to dict.setdefault (#938)
authorMichael Selik <mike@selik.org>
Sun, 2 Apr 2017 06:02:31 +0000 (02:02 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sun, 2 Apr 2017 06:02:31 +0000 (23:02 -0700)
* change LBYL key lookup to dict.setdefault

The ``results`` was constructed as a defaultdict and we could simply
delete the check ``if key not in results``. However, I think it's safer
to use dict.setdefault as I'm not sure whether the caller expects a
regular dict or defaultdict.

* add name to the acknowledgements file

* use defaultdict to make the key-lookup cleaner

Lib/lib2to3/btm_matcher.py
Misc/ACKS

index eabe1a71a654acb76434d0ceab6b214069e26170..3b78868038bda0733f03995e3f31c517c17bdc00 100644 (file)
@@ -117,10 +117,7 @@ class BottomMatcher(object):
                     #token matches
                     current_ac_node = current_ac_node.transition_table[node_token]
                     for fixer in current_ac_node.fixers:
-                        if not fixer in results:
-                            results[fixer] = []
                         results[fixer].append(current_ast_node)
-
                 else:
                     #matching failed, reset automaton
                     current_ac_node = self.root
@@ -134,8 +131,6 @@ class BottomMatcher(object):
                         #token matches
                         current_ac_node = current_ac_node.transition_table[node_token]
                         for fixer in current_ac_node.fixers:
-                            if not fixer in results.keys():
-                                results[fixer] = []
                             results[fixer].append(current_ast_node)
 
                 current_ast_node = current_ast_node.parent
index 21642065f43810a098e6edac8a7e83bba044c548..379ffc554ad92bc8b3413e27707ef678ab10d8e5 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1376,6 +1376,7 @@ Steven Scott
 Nick Seidenman
 Michael Seifert
 Žiga Seilnacht
+Michael Selik
 Yury Selivanov
 Fred Sells
 Jiwon Seo