Skip to content

Commit

Permalink
bpo-29638: Fix spurious refleaks after typing is imported (#469) (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilevkivskyi authored and serhiy-storchaka committed Mar 5, 2017
1 parent 3405792 commit b414e34
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Lib/test/libregrtest/refleak.py
Expand Up @@ -143,9 +143,14 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
sys._clear_type_cache()

# Clear ABC registries, restoring previously saved ABC registries.
for abc in [getattr(collections.abc, a) for a in collections.abc.__all__]:
if not isabstract(abc):
continue
abs_classes = [getattr(collections.abc, a) for a in collections.abc.__all__]
abs_classes = filter(isabstract, abs_classes)
if 'typing' in sys.modules:
t = sys.modules['typing']
# These classes require special treatment because they do not appear
# in direct subclasses of collections.abc classes
abs_classes = list(abs_classes) + [t.ChainMap, t.Counter, t.DefaultDict]
for abc in abs_classes:
for obj in abc.__subclasses__() + [abc]:
obj._abc_registry = abcs.get(obj, WeakSet()).copy()
obj._abc_cache.clear()
Expand Down

0 comments on commit b414e34

Please sign in to comment.