diff options
author | Ivan Levkivskyi <levkivskyi@gmail.com> | 2017-03-05 19:18:43 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-05 19:18:43 (GMT) |
commit | b414e349eb6a6140a81ccec249bae3abe939e836 (patch) | |
tree | 9c58b59b66c29134e1bdfd5a583a883b2e59c0c4 | |
parent | 3405792b024e9c6b70c0d2355c55a23ac84e1e67 (diff) | |
download | cpython-b414e349eb6a6140a81ccec249bae3abe939e836.zip cpython-b414e349eb6a6140a81ccec249bae3abe939e836.tar.gz cpython-b414e349eb6a6140a81ccec249bae3abe939e836.tar.bz2 |
bpo-29638: Fix spurious refleaks after typing is imported (#469) (#483)
-rw-r--r-- | Lib/test/libregrtest/refleak.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/test/libregrtest/refleak.py b/Lib/test/libregrtest/refleak.py index 3b3d245..e2e58bd 100644 --- a/Lib/test/libregrtest/refleak.py +++ b/Lib/test/libregrtest/refleak.py @@ -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() |