Kaydet (Commit) ab7cc759 authored tarafından Yury Selivanov's avatar Yury Selivanov

Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses.

Patch by Ethan Furman.
üst a78ebe63
...@@ -551,7 +551,7 @@ def _c3_merge(sequences): ...@@ -551,7 +551,7 @@ def _c3_merge(sequences):
break # reject the current head, it appears later break # reject the current head, it appears later
else: else:
break break
if not candidate: if candidate is None:
raise RuntimeError("Inconsistent hierarchy") raise RuntimeError("Inconsistent hierarchy")
result.append(candidate) result.append(candidate)
# remove the chosen candidate # remove the chosen candidate
......
...@@ -1328,6 +1328,24 @@ class TestSingleDispatch(unittest.TestCase): ...@@ -1328,6 +1328,24 @@ class TestSingleDispatch(unittest.TestCase):
many_abcs = [c.Mapping, c.Sized, c.Callable, c.Container, c.Iterable] many_abcs = [c.Mapping, c.Sized, c.Callable, c.Container, c.Iterable]
self.assertEqual(mro(X, abcs=many_abcs), expected) 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): def test_mro_conflicts(self):
c = collections c = collections
@functools.singledispatch @functools.singledispatch
......
...@@ -392,6 +392,9 @@ Library ...@@ -392,6 +392,9 @@ Library
- Issue #24298: Fix inspect.signature() to correctly unwrap wrappers - Issue #24298: Fix inspect.signature() to correctly unwrap wrappers
around bound methods. around bound methods.
- Issue #23572: Fixed functools.singledispatch on classes with falsy
metaclasses. Patch by Ethan Furman.
IDLE IDLE
---- ----
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment