]> granicus.if.org Git - python/commitdiff
bpo-29638: Fix spurious refleaks after typing is imported (#469) (#483)
authorIvan Levkivskyi <levkivskyi@gmail.com>
Sun, 5 Mar 2017 19:18:43 +0000 (20:18 +0100)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 5 Mar 2017 19:18:43 +0000 (21:18 +0200)
Lib/test/libregrtest/refleak.py

index 3b3d2458b1f2e0975829c1557ab76a733a887e9e..e2e58bd872f094cdf12a3faa56b5e36d9c5daf28 100644 (file)
@@ -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()