浏览代码

Improve the magic module check.

Ionel Cristian Mărieș 9 年之前
父节点
当前提交
d7648985b3
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      celery/tests/case.py

+ 9 - 4
celery/tests/case.py

@@ -232,10 +232,15 @@ def _is_magic_module(m):
     # will load _tkinter and other shit when touched.
 
     # pyflakes refuses to accept 'noqa' for this isinstance.
-    cls, modtype = getattr(m, '__class__', None), types.ModuleType
-    return (cls is not modtype and (
-        '__getattr__' in vars(m.__class__) or
-        '__getattribute__' in vars(m.__class__)))
+    cls, modtype = type(m), types.ModuleType
+    try:
+        variables = vars(cls)
+    except TypeError:
+        return True
+    else:
+        return (cls is not modtype and (
+            '__getattr__' in variables or
+            '__getattribute__' in variables))
 
 
 class _AssertWarnsContext(_AssertRaisesBaseContext):