[Python-checkins] cpython (3.4): Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses.
yury.selivanov
python-checkins at python.org
Tue Aug 18 20:33:08 CEST 2015
https://hg.python.org/cpython/rev/586195685aaf
changeset: 97445:586195685aaf
branch: 3.4
parent: 97440:010264c9ceae
user: Yury Selivanov <yselivanov at sprymix.com>
date: Tue Aug 18 14:30:15 2015 -0400
summary:
Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses.
Patch by Ethan Furman.
files:
Lib/functools.py | 2 +-
Lib/test/test_functools.py | 18 ++++++++++++++++++
Misc/NEWS | 3 +++
3 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/Lib/functools.py b/Lib/functools.py
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -551,7 +551,7 @@
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
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -1328,6 +1328,24 @@
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -392,6 +392,9 @@
- 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
----
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list