Skip to content

Commit 11fa3c7

Browse files
selikbenjaminp
authored andcommitted
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
1 parent 64c887a commit 11fa3c7

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

Lib/lib2to3/btm_matcher.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ def run(self, leaves):
117117
#token matches
118118
current_ac_node = current_ac_node.transition_table[node_token]
119119
for fixer in current_ac_node.fixers:
120-
if not fixer in results:
121-
results[fixer] = []
122120
results[fixer].append(current_ast_node)
123-
124121
else:
125122
#matching failed, reset automaton
126123
current_ac_node = self.root
@@ -134,8 +131,6 @@ def run(self, leaves):
134131
#token matches
135132
current_ac_node = current_ac_node.transition_table[node_token]
136133
for fixer in current_ac_node.fixers:
137-
if not fixer in results.keys():
138-
results[fixer] = []
139134
results[fixer].append(current_ast_node)
140135

141136
current_ast_node = current_ast_node.parent

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ Steven Scott
13761376
Nick Seidenman
13771377
Michael Seifert
13781378
Žiga Seilnacht
1379+
Michael Selik
13791380
Yury Selivanov
13801381
Fred Sells
13811382
Jiwon Seo

0 commit comments

Comments
 (0)