]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses.
authorYury Selivanov <yselivanov@sprymix.com>
Tue, 18 Aug 2015 18:20:00 +0000 (14:20 -0400)
committerYury Selivanov <yselivanov@sprymix.com>
Tue, 18 Aug 2015 18:20:00 +0000 (14:20 -0400)
Patch by Ethan Furman.

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

index 09df0680208c60743ccc4234a2eacd2fa373f214..06a4ff13664df0925aa4f9fc07c609752274b977 100644 (file)
@@ -567,7 +567,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 ac211c46ad6e8bf6dea916d27c6f0d868f206528..ae929eca99f281b02b0a9e9514bd96bb613732e9 100644 (file)
@@ -1491,6 +1491,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 10948818a62055f9d1079efde0a83642ceee9387..d523232ee698211915b79b28ba3b111187bbbb74 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,6 +2,29 @@
 Python News
 +++++++++++
 
+
+What's New in Python 3.5.1
+==========================
+
+
+Release date: TBA
+
+
+Core and Builtins
+-----------------
+
+
+Library
+-------
+
+- Issue #23572: Fixed functools.singledispatch on classes with falsy
+  metaclasses.  Patch by Ethan Furman.
+
+
+Documentation
+-------------
+
+
 What's New in Python 3.5.0 release candidate 2?
 ===============================================