Skip to content

Commit a6bff7e

Browse files
committed
Presented FreezableDefaultDict from jaraco.collections. Keep inline to minimize dependencies.
1 parent d84930c commit a6bff7e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

importlib_metadata/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import contextlib
1515
import collections
1616

17-
from ._collections import freezable_defaultdict
17+
from ._collections import FreezableDefaultDict
1818
from ._compat import (
1919
NullFinder,
2020
Protocol,
@@ -659,8 +659,8 @@ class Lookup:
659659
def __init__(self, path: FastPath):
660660
base = os.path.basename(path.root).lower()
661661
base_is_egg = base.endswith(".egg")
662-
self.infos = freezable_defaultdict(list)
663-
self.eggs = freezable_defaultdict(list)
662+
self.infos = FreezableDefaultDict(list)
663+
self.eggs = FreezableDefaultDict(list)
664664

665665
for child in path.children():
666666
low = child.lower()

importlib_metadata/_collections.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import collections
22

33

4-
class freezable_defaultdict(collections.defaultdict):
4+
# from jaraco.collections 3.3
5+
class FreezableDefaultDict(collections.defaultdict):
56
"""
6-
Mix-in to freeze a defaultdict.
7+
Often it is desirable to prevent the mutation of
8+
a default dict after its initial construction, such
9+
as to prevent mutation during iteration.
710
8-
>>> dd = freezable_defaultdict(list)
11+
>>> dd = FreezableDefaultDict(list)
912
>>> dd[0].append('1')
1013
>>> dd.freeze()
1114
>>> dd[1]

0 commit comments

Comments
 (0)