File tree Expand file tree Collapse file tree 5 files changed +16
-2
lines changed Expand file tree Collapse file tree 5 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ API Reference
66.. autofunction :: retry
77.. autofunction :: retry_context
88.. autoclass :: Attempt
9+ :members: num
910
1011
1112Configuration
Original file line number Diff line number Diff line change @@ -81,6 +81,13 @@ class Attempt:
8181
8282 _t_attempt : _t .AttemptManager
8383
84+ @property
85+ def num (self ) -> int :
86+ """
87+ The number of the current attempt.
88+ """
89+ return self ._t_attempt .retry_state .attempt_number # type: ignore[no-any-return]
90+
8491 def __enter__ (self ) -> None :
8592 return self ._t_attempt .__enter__ () # type: ignore[no-any-return]
8693
Original file line number Diff line number Diff line change @@ -151,6 +151,9 @@ async def test_retry_block():
151151 async for attempt in stamina .retry_context (on = ValueError , wait_max = 0 ):
152152 with attempt :
153153 num_called += 1
154+
155+ assert num_called == attempt .num
156+
154157 if num_called < 2 :
155158 raise ValueError
156159
Original file line number Diff line number Diff line change @@ -124,6 +124,9 @@ def test_retry_block():
124124 for attempt in stamina .retry_context (on = ValueError , wait_max = 0 ):
125125 with attempt :
126126 i += 1
127+
128+ assert i == attempt .num
129+
127130 if i < 2 :
128131 raise ValueError
129132
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ def hook(
9898
9999for attempt in retry_context (on = ValueError , timeout = 13 ):
100100 with attempt :
101- ...
101+ x : int = attempt . num
102102
103103for attempt in retry_context (
104104 on = ValueError , timeout = dt .timedelta (seconds = 13.0 )
@@ -116,4 +116,4 @@ async def f() -> None:
116116 wait_jitter = one_sec ,
117117 ):
118118 with attempt :
119- ...
119+ pass
You can’t perform that action at this time.
0 commit comments