Skip to content

Commit

Permalink
bpo-29957: change LBYL key lookup to dict.setdefault (#938)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
selik authored and benjaminp committed Apr 2, 2017
1 parent 64c887a commit 11fa3c7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
5 changes: 0 additions & 5 deletions Lib/lib2to3/btm_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ def run(self, leaves):
#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
Expand All @@ -134,8 +131,6 @@ def run(self, leaves):
#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
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ Steven Scott
Nick Seidenman
Michael Seifert
Žiga Seilnacht
Michael Selik
Yury Selivanov
Fred Sells
Jiwon Seo
Expand Down

0 comments on commit 11fa3c7

Please sign in to comment.