From 2368d86ed1249505b10561e005fc57f4884619c1 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 8 Apr 2019 16:54:16 -0700 Subject: [PATCH] bpo-36565: Fix libregrtest for Python without builtin _abc (GH-12733) (GH-12734) Fix reference hunting (``python3 -m test -R 3:3``) when Python has no built-in abc module: fix _get_dump() reimplementation of libregrtest. (cherry picked from commit 79b5d29041bd85ea3baa050b3fa2481344ea35c9) Co-authored-by: Victor Stinner --- Lib/test/libregrtest/refleak.py | 8 ++++++-- .../next/Tests/2019-04-08-19-01-21.bpo-36565.2bxgtU.rst | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2019-04-08-19-01-21.bpo-36565.2bxgtU.rst diff --git a/Lib/test/libregrtest/refleak.py b/Lib/test/libregrtest/refleak.py index 6724488fcfb0..d68ea63b5b3c 100644 --- a/Lib/test/libregrtest/refleak.py +++ b/Lib/test/libregrtest/refleak.py @@ -8,9 +8,13 @@ from test import support try: from _abc import _get_dump except ImportError: + import weakref + def _get_dump(cls): - # For legacy Python version - return (cls._abc_registry, cls._abc_cache, + # Reimplement _get_dump() for pure-Python implementation of + # the abc module (Lib/_py_abc.py) + registry_weakrefs = set(weakref.ref(obj) for obj in cls._abc_registry) + return (registry_weakrefs, cls._abc_cache, cls._abc_negative_cache, cls._abc_negative_cache_version) diff --git a/Misc/NEWS.d/next/Tests/2019-04-08-19-01-21.bpo-36565.2bxgtU.rst b/Misc/NEWS.d/next/Tests/2019-04-08-19-01-21.bpo-36565.2bxgtU.rst new file mode 100644 index 000000000000..8a14d08ba88f --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-04-08-19-01-21.bpo-36565.2bxgtU.rst @@ -0,0 +1,2 @@ +Fix reference hunting (``python3 -m test -R 3:3``) when Python has no +built-in abc module. -- 2.47.3