]> granicus.if.org Git - python/commitdiff
Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses.
authorYury Selivanov <yselivanov@sprymix.com>
Tue, 18 Aug 2015 18:30:15 +0000 (14:30 -0400)
committerYury Selivanov <yselivanov@sprymix.com>
Tue, 18 Aug 2015 18:30:15 +0000 (14:30 -0400)
Patch by Ethan Furman.

Lib/functools.py
Lib/test/test_functools.py
Misc/NEWS

index 3e93a3dad44b0ae8e1ba656b620869374a06ad51..2c299d713344850aed24b99cb74c3d04a59dce90 100644 (file)
@@ -551,7 +551,7 @@ def _c3_merge(sequences):
                     break      # reject the current head, it appears later
             else:
                 break
-        if not candidate:
+        if candidate is None:
             raise RuntimeError("Inconsistent hierarchy")
         result.append(candidate)
         # remove the chosen candidate
index 36f154a7f568c7765ba3e1c19492335c99c62777..c0d24d8c3ea61d446c0673a82adcd7b555245595 100644 (file)
@@ -1328,6 +1328,24 @@ class TestSingleDispatch(unittest.TestCase):
         many_abcs = [c.Mapping, c.Sized, c.Callable, c.Container, c.Iterable]
         self.assertEqual(mro(X, abcs=many_abcs), expected)
 
+    def test_false_meta(self):
+        # see issue23572
+        class MetaA(type):
+            def __len__(self):
+                return 0
+        class A(metaclass=MetaA):
+            pass
+        class AA(A):
+            pass
+        @functools.singledispatch
+        def fun(a):
+            return 'base A'
+        @fun.register(A)
+        def _(a):
+            return 'fun A'
+        aa = AA()
+        self.assertEqual(fun(aa), 'fun A')
+
     def test_mro_conflicts(self):
         c = collections
         @functools.singledispatch
index 70c3e1dc0577ac3d86e0c59c2c8396b60b26d102..1a2aebf36578932735ec97502fc1160704f72c88 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -392,6 +392,9 @@ Library
 - Issue #24298: Fix inspect.signature() to correctly unwrap wrappers
   around bound methods.
 
+- Issue #23572: Fixed functools.singledispatch on classes with falsy
+  metaclasses.  Patch by Ethan Furman.
+
 IDLE
 ----