[gcdebug] Only ignore weakref.WeakKeyDictionary class on Python 2
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 29 Nov 2017 17:08:05 +0100
changeset 12232 24393ce335f5
parent 12231 55924e962cd7
child 12233 62918203b9fc
[gcdebug] Only ignore weakref.WeakKeyDictionary class on Python 2 From Python 3.5, this class fails isinstance check with the following error: :: cls = <class 'weakref.WeakKeyDictionary'>, instance = <functools._lru_list_elem object at 0x7f4331859a48> def __instancecheck__(cls, instance): """Override for isinstance(instance, cls).""" # Inline the cache checking > subclass = instance.__class__ E AssertionError: [<class 'AttributeError'> in gc] 'functools._lru_list_elem' object has no attribute '__class__' /usr/lib/python3.5/abc.py:181: AssertionError I have no clue why this happens, but it makes cubicweb.web.test.test_views.AutomaticWebTest.test_startup_views fail on Python 3.5. So only consider this class for Python 2.
cubicweb/_gcdebug.py
--- a/cubicweb/_gcdebug.py	Wed Nov 29 16:14:57 2017 +0100
+++ b/cubicweb/_gcdebug.py	Wed Nov 29 17:08:05 2017 +0100
@@ -19,6 +19,8 @@
 
 import gc, types, weakref
 
+from six import PY2
+
 from cubicweb.schema import CubicWebRelationSchema, CubicWebEntitySchema
 try:
     from cubicweb.web.request import _NeedAuthAccessMock
@@ -29,12 +31,16 @@
 
 IGNORE_CLASSES = (
     type, tuple, dict, list, set, frozenset, type(len),
-    weakref.ref, weakref.WeakKeyDictionary,
+    weakref.ref,
     listiterator,
     property, classmethod,
     types.ModuleType, types.FunctionType, types.MethodType,
     types.MemberDescriptorType, types.GetSetDescriptorType,
     )
+if PY2:
+    # weakref.WeakKeyDictionary fails isinstance check on Python 3.5.
+    IGNORE_CLASSES += (weakref.WeakKeyDictionary, )
+
 if _NeedAuthAccessMock is not None:
     IGNORE_CLASSES = IGNORE_CLASSES + (_NeedAuthAccessMock,)