Skip to content

Commit ead7e21

Browse files
committed
Avoid raising StopIteration for PEP-0479 compliance
1 parent c31c667 commit ead7e21

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

pydispatch/dispatch.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ class Foo(Dispatcher):
8484
__skip_initialized = True
8585
def __new__(cls, *args, **kwargs):
8686
def iter_bases(_cls):
87-
if _cls is object:
88-
raise StopIteration
89-
yield _cls
90-
for b in _cls.__bases__:
91-
for _cls_ in iter_bases(b):
92-
yield _cls_
87+
if _cls is not object:
88+
yield _cls
89+
for b in _cls.__bases__:
90+
for _cls_ in iter_bases(b):
91+
yield _cls_
9392
skip_initialized = Dispatcher._Dispatcher__skip_initialized
9493
if not skip_initialized or cls not in Dispatcher._Dispatcher__initialized_subclasses:
9594
props = {}

tests/test_subclass_init.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
import math
22
import time
3+
import warnings
4+
5+
def test_dispatcher_construction():
6+
from pydispatch import Dispatcher, Property
7+
8+
class A(Dispatcher):
9+
foo = Property()
10+
bar = Property()
11+
baz = Property()
12+
_events_ = [
13+
'on_stuff', 'on_more_stuff',
14+
]
15+
class B(A):
16+
a = Property()
17+
b = Property()
18+
c = Property()
19+
_events_ = [
20+
'on_even_more_stuff', 'on_one_more_thing'
21+
]
22+
23+
with warnings.catch_warnings(record=True) as w_list:
24+
warnings.simplefilter("always")
25+
a = A()
26+
b = B()
27+
for w in w_list:
28+
# Check for PEP-0479 (StopIteration) issues
29+
assert not issubclass(w.category, DeprecationWarning)
30+
assert not issubclass(w.category, PendingDeprecationWarning)
31+
assert len(w_list) == 0
32+
33+
a_prop_names = {'foo', 'bar', 'baz'}
34+
a_event_names = {'on_stuff', 'on_more_stuff'}
35+
assert a_prop_names == set(a._Dispatcher__property_events.keys())
36+
assert a_event_names == set(a._Dispatcher__events.keys())
37+
38+
b_prop_names = {'a', 'b', 'c'}
39+
b_prop_names |= a_prop_names
40+
b_event_names = {'on_even_more_stuff', 'on_one_more_thing'}
41+
b_event_names |= a_event_names
42+
43+
assert b_prop_names == set(b._Dispatcher__property_events.keys())
44+
assert b_event_names == set(b._Dispatcher__events.keys())
345

446
def test_subclass_new_timing():
547
from pydispatch import Dispatcher, Property

0 commit comments

Comments
 (0)