@@ -35,8 +35,7 @@ class Instruments(UserDict[str, dict[Instrument, None]]):
35
35
__slots__ = ()
36
36
37
37
def __init__ (self , incoming : Sequence [Instrument ]) -> None :
38
- super ().__init__ ({})
39
- self ["_all" ] = {}
38
+ super ().__init__ ({"_all" : {}})
40
39
for instrument in incoming :
41
40
self .add_instrument (instrument )
42
41
@@ -50,9 +49,9 @@ def add_instrument(self, instrument: Instrument) -> None:
50
49
If ``instrument`` is already active, does nothing.
51
50
52
51
"""
53
- if instrument in self ["_all" ]:
52
+ if instrument in self . data ["_all" ]:
54
53
return
55
- self ["_all" ][instrument ] = None
54
+ self . data ["_all" ][instrument ] = None
56
55
try :
57
56
for name in dir (instrument ):
58
57
if name .startswith ("_" ):
@@ -65,7 +64,7 @@ def add_instrument(self, instrument: Instrument) -> None:
65
64
if isinstance (impl , types .MethodType ) and impl .__func__ is prototype :
66
65
# Inherited unchanged from _abc.Instrument
67
66
continue
68
- self .setdefault (name , {})[instrument ] = None
67
+ self .data . setdefault (name , {})[instrument ] = None
69
68
except :
70
69
self .remove_instrument (instrument )
71
70
raise
@@ -85,12 +84,12 @@ def remove_instrument(self, instrument: Instrument) -> None:
85
84
86
85
"""
87
86
# If instrument isn't present, the KeyError propagates out
88
- self ["_all" ].pop (instrument )
89
- for hookname , instruments in list (self .items ()):
87
+ self . data ["_all" ].pop (instrument )
88
+ for hookname , instruments in list (self .data . items ()):
90
89
if instrument in instruments :
91
90
del instruments [instrument ]
92
91
if not instruments :
93
- del self [hookname ]
92
+ del self . data [hookname ]
94
93
95
94
def call (
96
95
self ,
@@ -105,7 +104,7 @@ def call(
105
104
if "before_task_step" in instruments:
106
105
instruments.call("before_task_step", task)
107
106
"""
108
- for instrument in list (self [hookname ]):
107
+ for instrument in list (self . data [hookname ]):
109
108
try :
110
109
getattr (instrument , hookname )(* args )
111
110
except BaseException :
0 commit comments