changeset: 97445:586195685aaf branch: 3.4 parent: 97440:010264c9ceae user: Yury Selivanov date: Tue Aug 18 14:30:15 2015 -0400 files: Lib/functools.py Lib/test/test_functools.py Misc/NEWS description: Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses. Patch by Ethan Furman. diff -r 010264c9ceae -r 586195685aaf Lib/functools.py --- a/Lib/functools.py Tue Aug 18 13:26:57 2015 -0400 +++ b/Lib/functools.py Tue Aug 18 14:30:15 2015 -0400 @@ -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 -r 010264c9ceae -r 586195685aaf Lib/test/test_functools.py --- a/Lib/test/test_functools.py Tue Aug 18 13:26:57 2015 -0400 +++ b/Lib/test/test_functools.py Tue Aug 18 14:30:15 2015 -0400 @@ -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 -r 010264c9ceae -r 586195685aaf Misc/NEWS --- a/Misc/NEWS Tue Aug 18 13:26:57 2015 -0400 +++ b/Misc/NEWS Tue Aug 18 14:30:15 2015 -0400 @@ -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 ----