Skip to content

Commit 1b3408f

Browse files
committed
Fix defaultdict
1 parent fd587bd commit 1b3408f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Lib/collections/_defaultdict.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ def __init__(self, *args, **kwargs):
1010

1111
def __missing__(self, key):
1212
if self.default_factory:
13-
return self.default_factory()
13+
val = self.default_factory()
1414
else:
1515
raise KeyError(key)
16+
self[key] = val
17+
return val
1618

1719
def __repr__(self):
1820
return f"defaultdict({self.default_factory}, {dict.__repr__(self)})"

0 commit comments

Comments
 (0)