We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dd155e5 commit 1796719Copy full SHA for 1796719
dynamic_dispatch/_class.py
@@ -65,7 +65,7 @@ class Registered(wrap):
65
66
def __init__(self, *args, **kwargs):
67
# Certain scenarios can cause __init__ to be called twice. This prevents it.
68
- if not self.__dispatch_init:
+ if self.__class__ == __class__ and not self.__dispatch_init:
69
return
70
71
self.__dispatch_init = False
tests/test_class.py
@@ -541,3 +541,31 @@ def __init__(self, a):
541
self.assertEqual(obj.abc_count, 1)
542
self.assertEqual(obj.a, 5)
543
self.assertEqual(obj.a_count, 1)
544
+
545
+ def test_dispatch_twice_derived(self):
546
+ @dynamic_dispatch
547
+ class Foo(OneArgInit):
548
+ pass
549
550
+ @Foo.dispatch(on='bar')
551
+ class Bar(Foo):
552
+ def __init__(self, abc, d):
553
+ super().__init__(abc)
554
+ self.d = d
555
+ self.d_count = getattr(self, 'b_count', 0) + 1
556
557
+ @Foo.dispatch(on='baz')
558
+ class Baz(Bar):
559
+ def __init__(self, abc, d, e):
560
+ super().__init__(abc, d)
561
+ self.e = e
562
+ self.e_count = getattr(self, 'e_count', 0) + 1
563
564
+ obj = Foo('baz', 'd', 'e')
565
+ self.assertIsInstance(obj, Baz)
566
+ self.assertEqual(obj.abc, 'baz')
567
+ self.assertEqual(obj.abc_count, 1)
568
+ self.assertEqual(obj.d, 'd')
569
+ self.assertEqual(obj.d_count, 1)
570
+ self.assertEqual(obj.e, 'e')
571
+ self.assertEqual(obj.e_count, 1)
0 commit comments