summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-08-18 18:20:00 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-08-18 18:20:00 (GMT)
commit77a8cd65bed54ac07b264cd8eb26bc0da4d60130 (patch)
tree4505972d1ec398336ab59f2c6bf9512a0d7ebde7
parentf5e0c41d6d143b16af4b9d97d5ce39eaa9e32df3 (diff)
downloadcpython-77a8cd65bed54ac07b264cd8eb26bc0da4d60130.zip
cpython-77a8cd65bed54ac07b264cd8eb26bc0da4d60130.tar.gz
cpython-77a8cd65bed54ac07b264cd8eb26bc0da4d60130.tar.bz2
Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses.
Patch by Ethan Furman.
-rw-r--r--Lib/functools.py2
-rw-r--r--Lib/test/test_functools.py18
-rw-r--r--Misc/NEWS23
3 files changed, 42 insertions, 1 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 09df068..06a4ff1 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -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
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index ac211c4..ae929ec 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -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
diff --git a/Misc/NEWS b/Misc/NEWS
index 1094881..d523232 100644
--- 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?
===============================================