Skip to content

Commit 7acffa2

Browse files
ilevkivskyiserhiy-storchaka
authored andcommitted
bpo-29638: Fix spurious refleaks after typing is imported (#469)
1 parent c6b448b commit 7acffa2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Lib/test/libregrtest/refleak.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,14 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
143143
sys._clear_type_cache()
144144

145145
# Clear ABC registries, restoring previously saved ABC registries.
146-
for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]:
147-
if not isabstract(abc):
148-
continue
146+
abs_classes = [getattr(collections.abc, a) for a in collections.abc.__all__]
147+
abs_classes = filter(isabstract, abs_classes)
148+
if 'typing' in sys.modules:
149+
t = sys.modules['typing']
150+
# These classes require special treatment because they do not appear
151+
# in direct subclasses of collections.abc classes
152+
abs_classes = list(abs_classes) + [t.ChainMap, t.Counter, t.DefaultDict]
153+
for abc in abs_classes:
149154
for obj in abc.__subclasses__() + [abc]:
150155
obj._abc_registry = abcs.get(obj, WeakSet()).copy()
151156
obj._abc_cache.clear()

0 commit comments

Comments
 (0)