@@ -44,20 +44,20 @@ def __init__( # noqa: PLR0913
44
44
self ._selector = selector
45
45
self ._comparator = comparator
46
46
self ._func = func
47
- self .options = options
47
+ self ._options = options
48
48
49
49
self ._last_selector_result : SelectorOutput | None = None
50
50
self ._last_comparator_result : ComparatorOutput = cast (
51
51
ComparatorOutput ,
52
52
object (),
53
53
)
54
- self ._last_value : AutorunOriginalReturnType | None = options .default_value
54
+ self ._latest_value : AutorunOriginalReturnType | None = options .default_value
55
55
self ._subscriptions : set [
56
56
Callable [[AutorunOriginalReturnType ], Any ]
57
57
| weakref .ref [Callable [[AutorunOriginalReturnType ], Any ]]
58
58
] = set ()
59
59
60
- if self .options .initial_run and store ._state is not None : # noqa: SLF001
60
+ if self ._options .initial_run and store ._state is not None : # noqa: SLF001
61
61
self .check_and_call (store ._state ) # noqa: SLF001
62
62
63
63
store .subscribe (self .check_and_call )
@@ -76,12 +76,12 @@ def check_and_call(self: Autorun, state: State) -> None:
76
76
self ._last_selector_result = selector_result
77
77
self ._last_comparator_result = comparator_result
78
78
if len (signature (self ._func ).parameters ) == 1 :
79
- last_value = cast (
79
+ self . _latest_value = cast (
80
80
Callable [[SelectorOutput ], AutorunOriginalReturnType ],
81
81
self ._func ,
82
82
)(selector_result )
83
83
else :
84
- last_value = cast (
84
+ self . _latest_value = cast (
85
85
Callable [
86
86
[SelectorOutput , SelectorOutput | None ],
87
87
AutorunOriginalReturnType ,
@@ -99,7 +99,7 @@ def check_and_call(self: Autorun, state: State) -> None:
99
99
continue
100
100
else :
101
101
subscriber = subscriber_
102
- subscriber (last_value )
102
+ subscriber (self . _latest_value )
103
103
104
104
def __call__ (
105
105
self : Autorun [
@@ -113,7 +113,20 @@ def __call__(
113
113
) -> AutorunOriginalReturnType :
114
114
if self ._store ._state is not None : # noqa: SLF001
115
115
self .check_and_call (self ._store ._state ) # noqa: SLF001
116
- return cast (AutorunOriginalReturnType , self ._last_value )
116
+ return cast (AutorunOriginalReturnType , self ._latest_value )
117
+
118
+ def __repr__ (
119
+ self : Autorun [
120
+ State ,
121
+ Action ,
122
+ Event ,
123
+ SelectorOutput ,
124
+ ComparatorOutput ,
125
+ AutorunOriginalReturnType ,
126
+ ],
127
+ ) -> str :
128
+ return f"""{ super ().__repr__ ()} (func: { self ._func } , last_value: {
129
+ self ._latest_value } )"""
117
130
118
131
@property
119
132
def value (
@@ -126,7 +139,7 @@ def value(
126
139
AutorunOriginalReturnType ,
127
140
],
128
141
) -> AutorunOriginalReturnType :
129
- return cast (AutorunOriginalReturnType , self ._last_value )
142
+ return cast (AutorunOriginalReturnType , self ._latest_value )
130
143
131
144
def subscribe (
132
145
self : Autorun [
@@ -143,9 +156,9 @@ def subscribe(
143
156
keep_ref : bool | None = None ,
144
157
) -> Callable [[], None ]:
145
158
if immediate_run is None :
146
- immediate_run = self .options .subscribers_immediate_run
159
+ immediate_run = self ._options .subscribers_immediate_run
147
160
if keep_ref is None :
148
- keep_ref = self .options .subscribers_keep_ref
161
+ keep_ref = self ._options .subscribers_keep_ref
149
162
if keep_ref :
150
163
callback_ref = callback
151
164
elif isinstance (callback , MethodType ):
0 commit comments