Kaydet (Commit) 11fa3c7c authored tarafından Michael Selik's avatar Michael Selik Kaydeden (comit) Benjamin Peterson

bpo-29957: change LBYL key lookup to dict.setdefault (#938)

* 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
üst 64c887ab
...@@ -117,10 +117,7 @@ class BottomMatcher(object): ...@@ -117,10 +117,7 @@ class BottomMatcher(object):
#token matches #token matches
current_ac_node = current_ac_node.transition_table[node_token] current_ac_node = current_ac_node.transition_table[node_token]
for fixer in current_ac_node.fixers: for fixer in current_ac_node.fixers:
if not fixer in results:
results[fixer] = []
results[fixer].append(current_ast_node) results[fixer].append(current_ast_node)
else: else:
#matching failed, reset automaton #matching failed, reset automaton
current_ac_node = self.root current_ac_node = self.root
...@@ -134,8 +131,6 @@ class BottomMatcher(object): ...@@ -134,8 +131,6 @@ class BottomMatcher(object):
#token matches #token matches
current_ac_node = current_ac_node.transition_table[node_token] current_ac_node = current_ac_node.transition_table[node_token]
for fixer in current_ac_node.fixers: for fixer in current_ac_node.fixers:
if not fixer in results.keys():
results[fixer] = []
results[fixer].append(current_ast_node) results[fixer].append(current_ast_node)
current_ast_node = current_ast_node.parent current_ast_node = current_ast_node.parent
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment