Skip to content

Commit

Permalink
Issue python#23572: Fixed functools.singledispatch on classes with fa…
Browse files Browse the repository at this point in the history
…lsy metaclasses.

Patch by Ethan Furman.
  • Loading branch information
1st1 committed Aug 18, 2015
1 parent a78ebe6 commit ab7cc75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,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
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,24 @@ def __call__(self):
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
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ Library
- 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
----

Expand Down

0 comments on commit ab7cc75

Please sign in to comment.