Skip to content

Commit 77a8cd6

Browse files
committed
Issue #23572: Fixed functools.singledispatch on classes with falsy metaclasses.
Patch by Ethan Furman.
1 parent f5e0c41 commit 77a8cd6

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Lib/functools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def _c3_merge(sequences):
567567
break # reject the current head, it appears later
568568
else:
569569
break
570-
if not candidate:
570+
if candidate is None:
571571
raise RuntimeError("Inconsistent hierarchy")
572572
result.append(candidate)
573573
# remove the chosen candidate

Lib/test/test_functools.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,24 @@ def __call__(self):
14911491
many_abcs = [c.Mapping, c.Sized, c.Callable, c.Container, c.Iterable]
14921492
self.assertEqual(mro(X, abcs=many_abcs), expected)
14931493

1494+
def test_false_meta(self):
1495+
# see issue23572
1496+
class MetaA(type):
1497+
def __len__(self):
1498+
return 0
1499+
class A(metaclass=MetaA):
1500+
pass
1501+
class AA(A):
1502+
pass
1503+
@functools.singledispatch
1504+
def fun(a):
1505+
return 'base A'
1506+
@fun.register(A)
1507+
def _(a):
1508+
return 'fun A'
1509+
aa = AA()
1510+
self.assertEqual(fun(aa), 'fun A')
1511+
14941512
def test_mro_conflicts(self):
14951513
c = collections
14961514
@functools.singledispatch

Misc/NEWS

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22
Python News
33
+++++++++++
44

5+
6+
What's New in Python 3.5.1
7+
==========================
8+
9+
10+
Release date: TBA
11+
12+
13+
Core and Builtins
14+
-----------------
15+
16+
17+
Library
18+
-------
19+
20+
- Issue #23572: Fixed functools.singledispatch on classes with falsy
21+
metaclasses. Patch by Ethan Furman.
22+
23+
24+
Documentation
25+
-------------
26+
27+
528
What's New in Python 3.5.0 release candidate 2?
629
===============================================
730

0 commit comments

Comments
 (0)