reykit 1.1.40__py3-none-any.whl → 1.1.42__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
reykit/__init__.py CHANGED
File without changes
reykit/rall.py CHANGED
File without changes
reykit/rbase.py CHANGED
@@ -946,7 +946,7 @@ def at_exit(*contents: str | Callable | tuple[Callable, Iterable, Mapping]) -> l
946
946
  args = ()
947
947
  kwargs = {}
948
948
  if type(content) == str:
949
- func = lambda : print(content)
949
+ func = lambda: print(content)
950
950
  elif callable(content):
951
951
  func = content
952
952
  elif type(content) == tuple:
reykit/rdata.py CHANGED
@@ -362,7 +362,7 @@ def default_dict(default: T = null, data: dict[KT, VT] | None = None) -> Default
362
362
 
363
363
  ## Not callable.
364
364
  else:
365
- default_factory = lambda : default
365
+ default_factory = lambda: default
366
366
 
367
367
  if data is None:
368
368
  data = {}
reykit/rdll/__init__.py CHANGED
File without changes
reykit/rdll/rdll_core.py CHANGED
File without changes
reykit/remail.py CHANGED
File without changes
reykit/rimage.py CHANGED
File without changes
reykit/rlog.py CHANGED
File without changes
reykit/rmonkey.py CHANGED
File without changes
reykit/rnet.py CHANGED
File without changes
reykit/rnum.py CHANGED
File without changes
reykit/ros.py CHANGED
File without changes
reykit/rrand.py CHANGED
File without changes
reykit/rre.py CHANGED
File without changes
reykit/rschedule.py CHANGED
File without changes
reykit/rstdout.py CHANGED
File without changes
reykit/rsys.py CHANGED
File without changes
reykit/rtable.py CHANGED
File without changes
reykit/rtask.py CHANGED
File without changes
reykit/rtext.py CHANGED
File without changes
reykit/rtime.py CHANGED
File without changes
reykit/rwrap.py CHANGED
@@ -10,21 +10,23 @@
10
10
 
11
11
 
12
12
  from typing import Any, Literal, overload
13
+ from types import TracebackType
13
14
  from collections.abc import Callable
14
15
  from io import IOBase, StringIO
15
- from inspect import getdoc
16
- from functools import wraps as functools_wraps
16
+ from inspect import getdoc as inspect_getdoc
17
+ from functools import wraps as functools_wraps, partial as functools_partial
18
+ from datetime import datetime as Datetime, timedelta as Timedelta
17
19
  from threading import Thread
18
20
  from argparse import ArgumentParser
19
21
  from contextlib import redirect_stdout
20
22
 
21
- from .rbase import catch_exc, get_arg_info
23
+ from .rbase import T, catch_exc, get_arg_info
22
24
  from .rstdout import echo
23
25
  from .rtime import now, time_to, TimeMark
24
26
 
25
27
 
26
28
  __all__ = (
27
- 'wrap_frame',
29
+ 'wrap_wrap',
28
30
  'wrap_runtime',
29
31
  'wrap_thread',
30
32
  'wrap_exc',
@@ -36,13 +38,17 @@ __all__ = (
36
38
  )
37
39
 
38
40
 
39
- def wrap_frame(decorator: Callable) -> Callable:
41
+ type Decorated = Callable
42
+ type Decorator = Callable[..., Decorated]
43
+
44
+
45
+ def wrap_wrap(decorator: Decorator) -> Decorator:
40
46
  """
41
- Decorative frame.
47
+ Decorate decorator.
42
48
 
43
49
  Parameters
44
50
  ----------
45
- decorator : Decorator function.
51
+ decorator : Decorator.
46
52
 
47
53
  Retuens
48
54
  -------
@@ -50,140 +56,138 @@ def wrap_frame(decorator: Callable) -> Callable:
50
56
 
51
57
  Examples
52
58
  --------
53
- Decoration function method one.
59
+ >>> @wrap_wrap
60
+ >>> def wrap_func(func, args, kwargs, **wrap_kwargs): ...
61
+
62
+ Method one.
54
63
  >>> @wrap_func
55
- >>> def func(): ...
56
- >>> result = func(param_a, param_b, param_c=1, param_d=2)
57
-
58
- Decoration function method two.
59
- >>> def func(): ...
60
- >>> result = wrap_func(func, param_a, param_b, param_c=1, param_d=2)
61
-
62
- Decoration function method three.
63
- >>> def func(): ...
64
- >>> result = wrap_func(func, _execute=True)
65
-
66
- Decoration function method four.
67
- >>> def func(): ...
64
+ >>> def func(*args, **kwargs): ...
65
+
66
+ Method two.
67
+ >>> @wrap_func(**wrap_kwargs)
68
+ >>> def func(*args, **kwargs): ...
69
+
70
+ Method three.
71
+ >>> def func(*args, **kwargs): ...
72
+ >>> func = wrap_func(func, **wrap_kwargs)
73
+
74
+ Method four.
75
+ >>> def func(*args, **kwargs): ...
76
+ >>> wrap_func = wrap_func(**wrap_kwargs)
68
77
  >>> func = wrap_func(func)
69
- >>> result = func(param_a, param_b, param_c=1, param_d=2)
70
78
 
71
- Decoration function method five.
72
- >>> def func(): ...
73
- >>> func = wrap_func(func, param_a, param_c=1, _execute=False)
74
- >>> result = func(param_b, param_d=2)
79
+ >>> func(*args, **kwargs)
75
80
  """
76
81
 
77
82
 
78
83
  # Decorate Decorator.
79
84
  @overload
80
- def wrap(func: Callable, /, *args: Any, **kwargs: Any) -> Callable | Any: ...
81
-
82
- @overload
83
- def wrap(func: Callable, /, *args: Any, _execute: Literal[True], **kwargs: Any) -> Any: ...
85
+ def _wrap(func: Callable, **wrap_kwargs: Any) -> Decorated: ...
84
86
 
85
87
  @overload
86
- def wrap(func: Callable, /, *args: Any, _execute: Literal[False], **kwargs: Any) -> Callable: ...
88
+ def _wrap(**wrap_kwargs: Any) -> Decorator: ...
87
89
 
88
90
  @functools_wraps(decorator)
89
- def wrap(func: Callable, /, *args: Any, _execute: bool | None = None, **kwargs: Any) -> Callable | Any:
91
+ def _wrap(func: Callable | None = None, **wrap_kwargs: Any) -> Decorated | Decorator:
90
92
  """
91
- Decorative shell.
93
+ Decorated decorator.
92
94
 
93
95
  Parameters
94
96
  ----------
95
97
  func : Function.
96
- args : Position arguments of function.
97
- _execute : Whether execute function, otherwise decorate function.
98
- - `None`, When parameter `args` or `kwargs`: have values, then True, otherwise False.
99
- - `bool`: Use this value.
100
- kwargs : Keyword arguments of function.
98
+ wrap_kwargs : Keyword arguments of decorator.
101
99
 
102
100
  Returns
103
101
  -------
104
- Decorated function or function return.
102
+ Decorated function or decorated self.
105
103
  """
106
104
 
107
- # Handle parameter.
108
- if _execute is None:
109
- if args != () or kwargs != {}:
110
- _execute = True
111
- else:
112
- _execute = False
105
+ # Method one and three.
106
+ if func is not None:
113
107
 
114
- # Direct execution.
115
- if _execute:
116
- result = decorator(func, *args, **kwargs)
117
- return result
118
108
 
109
+ @functools_wraps(func)
110
+ def _func(*args: Any, **kwargs: Any) -> Any:
111
+ """
112
+ Decorated function.
119
113
 
120
- # Decorate function.
121
- @functools_wraps(func)
122
- def wrap_sub(*_args: Any, **_kwargs: Any) -> Any:
123
- """
124
- Decorative sub shell.
114
+ Parameters
115
+ ----------
116
+ args : Position arguments of function.
117
+ kwargs : Keyword arguments of function.
125
118
 
126
- Parameters
127
- ----------
128
- args : Position arguments of function.
129
- kwargs : Keyword arguments of function.
119
+ Returns
120
+ -------
121
+ Function return.
122
+ """
130
123
 
131
- Returns
132
- -------
133
- Function return.
134
- """
124
+ # Decorate function.
125
+ result = decorator(func, args, kwargs, **wrap_kwargs)
135
126
 
136
- # Decorate function.
137
- result = decorator(func, *args, *_args, **kwargs, **_kwargs)
127
+ return result
138
128
 
139
- return result
129
+
130
+ return _func
140
131
 
141
132
 
142
- return wrap_sub
133
+ # Method two and four.
134
+ else:
135
+ __wrap = functools_partial(_wrap, **wrap_kwargs)
136
+ return __wrap
143
137
 
144
138
 
145
- return wrap
139
+ return _wrap
146
140
 
147
141
 
148
142
  @overload
149
143
  def wrap_runtime(
150
- func: Callable,
151
- /,
152
- *args: Any,
153
- _return_report: Literal[False] = False,
154
- **kwargs: Any
155
- ) -> Any: ...
144
+ func: Callable[..., T],
145
+ *,
146
+ to_print: bool = True
147
+ ) -> Callable[..., T]: ...
156
148
 
157
149
  @overload
158
150
  def wrap_runtime(
159
- func: Callable,
160
- /,
161
- *args: Any,
162
- _return_report: Literal[True],
163
- **kwargs: Any
164
- ) -> tuple[Any, str]: ...
151
+ func: Callable[..., T],
152
+ to_return: Literal[True],
153
+ to_print: bool = True
154
+ ) -> Callable[..., tuple[T, str, Datetime, Timedelta, Datetime]]: ...
165
155
 
166
- @wrap_frame
156
+ @overload
167
157
  def wrap_runtime(
168
- func: Callable,
169
- /,
170
- *args: Any,
171
- _return_report: bool = False,
172
- **kwargs: Any
173
- ) -> Any | tuple[Any, str]:
158
+ *,
159
+ to_print: bool = True
160
+ ) -> Callable[[Callable[..., T]], T]: ...
161
+
162
+ @overload
163
+ def wrap_runtime(
164
+ *,
165
+ to_return: Literal[True],
166
+ to_print: bool = True
167
+ ) -> Callable[[Callable[..., T]], tuple[T, str, Datetime, Timedelta, Datetime]]: ...
168
+
169
+ @wrap_wrap
170
+ def wrap_runtime(
171
+ func: Callable[..., T],
172
+ args: Any,
173
+ kwargs: Any,
174
+ to_return: bool = False,
175
+ to_print: bool = True
176
+ ) -> T | tuple[T, str, Datetime, Timedelta, Datetime]:
174
177
  """
175
- Decorator, print or return runtime report of the function.
178
+ Decorator, print or return runtime data of the function.
176
179
 
177
180
  Parameters
178
181
  ----------
179
- func : Function to be decorated.
180
- args : Position arguments of decorated function.
181
- _return_report : Whether return report, otherwise print report.
182
- kwargs : Keyword arguments of decorated function.
182
+ func : Function.
183
+ args : Position arguments of function.
184
+ kwargs : Keyword arguments of function.
185
+ to_print : Whether to print runtime.
186
+ to_return : Whether to return runtime.
183
187
 
184
188
  Returns
185
189
  -------
186
- Function execution result and runtime report.
190
+ Function return or runtime data.
187
191
  """
188
192
 
189
193
  # Execute function and marking time.
@@ -194,7 +198,7 @@ def wrap_runtime(
194
198
 
195
199
  # Generate report.
196
200
  start_time = rtm.record[0]['datetime']
197
- spend_time = rtm.record[1]['timedelta']
201
+ spend_time: Timedelta = rtm.record[1]['timedelta']
198
202
  end_time = rtm.record[1]['datetime']
199
203
  start_str = time_to(start_time, True)[:-3]
200
204
  spend_str = time_to(spend_time, True)[:-3]
@@ -206,12 +210,13 @@ def wrap_runtime(
206
210
  )
207
211
  title = func.__name__
208
212
 
209
- # Return report.
210
- if _return_report:
211
- return result, report
213
+ # Print.
214
+ if to_print:
215
+ echo(report, title=title)
212
216
 
213
- # Print report.
214
- echo(report, title=title)
217
+ # Return.
218
+ if to_return:
219
+ return result, report, start_time, spend_time, end_time
215
220
 
216
221
  return result
217
222
 
@@ -219,33 +224,35 @@ def wrap_runtime(
219
224
  @overload
220
225
  def wrap_thread(
221
226
  func: Callable,
222
- /,
223
- *args: Any,
224
- _daemon: bool = True,
225
- **kwargs: Any
226
- ) -> Thread: ...
227
+ daemon: bool = True
228
+ ) -> Callable[..., Thread]: ...
227
229
 
228
- @wrap_frame
230
+ @overload
231
+ def wrap_thread(
232
+ *,
233
+ daemon: bool = True
234
+ ) -> Callable[[Callable], Thread]: ...
235
+
236
+ @wrap_wrap
229
237
  def wrap_thread(
230
238
  func: Callable,
231
- /,
232
- *args: Any,
233
- _daemon: bool = True,
234
- **kwargs: Any
239
+ args: Any,
240
+ kwargs: Any,
241
+ daemon: bool = True
235
242
  ) -> Thread:
236
243
  """
237
244
  Decorator, function start in thread.
238
245
 
239
246
  Parameters
240
247
  ----------
241
- func : Function to be decorated.
242
- args : Position arguments of decorated function.
243
- _daemon : Whether it is a daemon thread.
244
- kwargs : Keyword arguments of decorated function.
248
+ func : Function.
249
+ args : Position arguments of function.
250
+ kwargs : Keyword arguments of function.
251
+ daemon : Whether it is a daemon thread.
245
252
 
246
253
  Returns
247
254
  -------
248
- Thread object.
255
+ Thread instance.
249
256
  """
250
257
 
251
258
  # Handle parameter.
@@ -253,7 +260,7 @@ def wrap_thread(
253
260
 
254
261
  # Create thread.
255
262
  thread = Thread(target=func, name=thread_name, args=args, kwargs=kwargs)
256
- thread.daemon = _daemon
263
+ thread.daemon = daemon
257
264
 
258
265
  # Start thread.
259
266
  thread.start()
@@ -263,37 +270,40 @@ def wrap_thread(
263
270
 
264
271
  @overload
265
272
  def wrap_exc(
266
- func: Callable,
267
- /,
268
- *args: Any,
269
- _exception: BaseException | tuple[BaseException, ...] = BaseException,
270
- _handler: Callable | None = None,
271
- **kwargs: Any
272
- ) -> Any | None: ...
273
-
274
- @wrap_frame
273
+ func: Callable[..., T],
274
+ handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any],
275
+ exception: BaseException | tuple[BaseException, ...] | None = BaseException
276
+ ) -> Callable[..., T | None]: ...
277
+
278
+ @overload
275
279
  def wrap_exc(
276
- func: Callable,
277
- /,
278
- *args: Any,
279
- _exception: BaseException | tuple[BaseException, ...] = BaseException,
280
- _handler: Callable | None = None,
281
- **kwargs: Any
282
- ) -> Any | None:
280
+ *,
281
+ handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any],
282
+ exception: BaseException | tuple[BaseException, ...] | None = BaseException
283
+ ) -> Callable[[Callable[..., T]], T | None]: ...
284
+
285
+ @wrap_wrap
286
+ def wrap_exc(
287
+ func: Callable[..., T],
288
+ args: Any,
289
+ kwargs: Any,
290
+ handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any],
291
+ exception: BaseException | tuple[BaseException, ...] | None = BaseException
292
+ ) -> T | None:
283
293
  """
284
- Decorator, execute function with `try` and `except` syntax.
294
+ Decorator, execute function with `try` syntax and handle exception.
285
295
 
286
296
  Parameters
287
297
  ----------
288
- func : Function to be decorated.
289
- args : Position arguments of decorated function.
290
- _exception : Catch exception types.
291
- _handler : Exception handler, will return value.
292
- kwargs : Keyword arguments of decorated function.
298
+ func : Function.
299
+ args : Position arguments of function.
300
+ kwargs : Keyword arguments of function.
301
+ handler : Exception handler.
302
+ exception : Catch exception type.
293
303
 
294
304
  Returns
295
305
  -------
296
- Execution result of function or exception handle method.
306
+ Function return.
297
307
  """
298
308
 
299
309
  # Execute function.
@@ -301,130 +311,112 @@ def wrap_exc(
301
311
  result = func(*args, **kwargs)
302
312
 
303
313
  # Handle exception.
304
- except _exception:
305
- if _handler is not None:
306
- result = _handler()
307
- else:
308
- result = None
314
+ except exception:
315
+ exc_report, exc_type, exc_instance, exc_traceback = catch_exc()
316
+ handler(exc_report, exc_type, exc_instance, exc_traceback)
309
317
 
310
- return result
318
+ else:
319
+ return result
311
320
 
312
321
 
313
322
  @overload
314
323
  def wrap_retry(
315
- func: Callable,
316
- /,
317
- *args: Any,
318
- _report: str | None = None,
319
- _exception: BaseException | tuple[BaseException, ...] = BaseException,
320
- _try_total: int = 1,
321
- _try_count: int = 0,
322
- **kwargs: Any
323
- ) -> Any: ...
324
-
325
- @wrap_frame
324
+ func: Callable[..., T],
325
+ total: int = 1,
326
+ handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any] | None = None,
327
+ exception: BaseException | tuple[BaseException, ...] = BaseException
328
+ ) -> Callable[..., T]: ...
329
+
330
+ @overload
326
331
  def wrap_retry(
327
- func: Callable,
328
- /,
329
- *args: Any,
330
- _report: str | None = None,
331
- _exception: BaseException | tuple[BaseException, ...] = BaseException,
332
- _try_total: int = 1,
333
- _try_count: int = 0,
334
- **kwargs: Any
335
- ) -> Any:
332
+ *,
333
+ total: int = 1,
334
+ handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any] | None = None,
335
+ exception: BaseException | tuple[BaseException, ...] = BaseException
336
+ ) -> Callable[[Callable[..., T]], T]: ...
337
+
338
+ @wrap_wrap
339
+ def wrap_retry(
340
+ func: Callable[..., T],
341
+ args: Any,
342
+ kwargs: Any,
343
+ total: int = 2,
344
+ handler: Callable[[tuple[str, type[BaseException], BaseException, TracebackType]], Any] | None = None,
345
+ exception: BaseException | tuple[BaseException, ...] = BaseException
346
+ ) -> T:
336
347
  """
337
- Decorator, try again.
348
+ Decorator, try again and handle exception.
338
349
 
339
350
  Parameters
340
351
  ----------
341
- func : Function to be decorated.
342
- args : Position arguments of decorated function.
343
- _report : Print report title.
344
- - `None`: Not print.
345
- - `str`: Print and use this title.
346
- _exception : Catch exception types.
347
- _try_total : Retry total.
348
- _try_count : Retry count.
349
- kwargs : Keyword arguments of decorated function.
352
+ func : Function.
353
+ args : Position arguments of function.
354
+ kwargs : Keyword arguments of function.
355
+ total : Retry total.
356
+ handler : Exception handler.
357
+ exception : Catch exception type.
350
358
 
351
359
  Returns
352
360
  -------
353
- Function execution result.
361
+ Function return.
354
362
  """
355
363
 
356
- # Try count not full.
357
- if _try_count < _try_total:
364
+ # Loop.
365
+ for _ in range(0, total - 1):
358
366
 
359
- ## Try.
367
+ # Try.
360
368
  try:
361
369
  result = func(*args, **kwargs)
362
- except _exception:
363
-
364
- ## Report.
365
- if _report is not None:
366
- exc_report, *_ = catch_exc()
367
- echo(
368
- exc_report,
369
- 'Retrying...',
370
- title=_report,
371
- frame='half'
372
- )
373
-
374
- ### Retry.
375
- _try_count += 1
376
- result = wrap_retry(
377
- func,
378
- *args,
379
- _report=_report,
380
- _exception=_exception,
381
- _try_total=_try_total,
382
- _try_count=_try_count,
383
- **kwargs
384
- )
385
370
 
386
- # Try count full.
387
- else:
388
- result = func(*args, **kwargs)
371
+ ## Handle.
372
+ except exception:
373
+ if handler is not None:
374
+ exc_report, exc_type, exc_instance, exc_traceback = catch_exc()
375
+ handler(exc_report, exc_type, exc_instance, exc_traceback)
376
+
377
+ else:
378
+ return result
379
+
380
+ # Last.
381
+ result = func(*args, **kwargs)
389
382
 
390
383
  return result
391
384
 
392
385
 
393
386
  @overload
394
387
  def wrap_dos_command(
395
- func: Callable,
396
- /,
397
- *args: Any,
398
- **kwargs: Any
399
- ) -> Any: ...
388
+ func: Callable[..., T]
389
+ ) -> Callable[..., T]: ...
390
+
391
+ @overload
392
+ def wrap_dos_command() -> Callable[[Callable[..., T]], T]: ...
400
393
 
401
- @wrap_frame
394
+ @wrap_wrap
402
395
  def wrap_dos_command(
403
- func: Callable,
404
- /,
405
- *args: Any,
406
- **kwargs: Any
407
- ) -> Any:
396
+ func: Callable[..., T],
397
+ args: Any,
398
+ kwargs: Any,
399
+ ) -> T:
408
400
  """
409
401
  Decorator, use DOS command to input arguments to function.
410
402
  Use DOS command `python file --help` to view help information.
411
403
 
412
404
  Parameters
413
405
  ----------
414
- func : Function to be decorated.
415
- args : Position arguments of decorated function.
416
- kwargs : Keyword arguments of decorated function.
406
+ func : Function.
407
+ args : Position arguments of function.
408
+ kwargs : Keyword arguments of function.
417
409
 
418
410
  Returns
419
411
  -------
420
- Function execution result.
412
+ Function return.
421
413
  """
422
414
 
423
415
  # Get parameter.
424
416
  arg_info = get_arg_info(func)
425
417
 
426
418
  # Set DOS command.
427
- usage = getdoc(func)
419
+ usage = inspect_getdoc(func)
428
420
  if usage is not None:
429
421
  usage = 'input arguments to function "%s"\n\n%s' % (func.__name__, usage)
430
422
  parser = ArgumentParser(usage=usage)
@@ -519,21 +511,23 @@ wrap_cache_data: dict[Callable, list[tuple[Any, Any, Any]]] = {}
519
511
 
520
512
  @overload
521
513
  def wrap_cache(
522
- func: Callable,
523
- /,
524
- *args: Any,
525
- _overwrite: bool = False,
526
- **kwargs: Any
527
- ) -> Any: ...
514
+ func: Callable[..., T],
515
+ overwrite: bool = False
516
+ ) -> Callable[..., T]: ...
528
517
 
529
- @wrap_frame
518
+ @overload
530
519
  def wrap_cache(
531
- func: Callable,
532
- /,
533
- *args: Any,
534
- _overwrite: bool = False,
535
- **kwargs: Any
536
- ) -> Any:
520
+ *,
521
+ overwrite: bool = False
522
+ ) -> Callable[[Callable[..., T]], T]: ...
523
+
524
+ @wrap_wrap
525
+ def wrap_cache(
526
+ func: Callable[..., T],
527
+ args: Any,
528
+ kwargs: Any,
529
+ overwrite: bool = False
530
+ ) -> T:
537
531
  """
538
532
  Decorator, Cache the return result of function input.
539
533
  if no cache, cache it.
@@ -541,14 +535,14 @@ def wrap_cache(
541
535
 
542
536
  Parameters
543
537
  ----------
544
- func : Function to be decorated.
545
- args : Position arguments of decorated function.
546
- _overwrite : Whether to overwrite cache.
547
- kwargs : Keyword arguments of decorated function.
538
+ func : Function.
539
+ args : Position arguments of function.
540
+ kwargs : Keyword arguments of function.
541
+ overwrite : Whether to overwrite cache.
548
542
 
549
543
  Returns
550
544
  -------
551
- Function execution result.
545
+ Function return.
552
546
  """
553
547
 
554
548
  # Index.
@@ -559,7 +553,7 @@ def wrap_cache(
559
553
  cache_args == args
560
554
  and cache_kwargs == kwargs
561
555
  ):
562
- if _overwrite:
556
+ if overwrite:
563
557
  cache_index = index
564
558
  break
565
559
  else:
@@ -580,39 +574,42 @@ def wrap_cache(
580
574
 
581
575
  @overload
582
576
  def wrap_redirect_stdout(
583
- func: Callable,
584
- /,
585
- *args: Any,
586
- _redirect: list | IOBase | None = None,
587
- **kwargs: Any
588
- ) -> Any: ...
577
+ func: Callable[..., T],
578
+ *,
579
+ redirect: list | IOBase | None = None
580
+ ) -> Callable[..., T]: ...
589
581
 
590
- @wrap_frame
582
+ @overload
591
583
  def wrap_redirect_stdout(
592
- func: Callable,
593
- /,
594
- *args: Any,
595
- _redirect: list | IOBase | None = None,
596
- **kwargs: Any
597
- ) -> Any:
584
+ *,
585
+ redirect: list | IOBase | None = None
586
+ ) -> Callable[[Callable[..., T]], T]: ...
587
+
588
+ @wrap_wrap
589
+ def wrap_redirect_stdout(
590
+ func: Callable[..., T],
591
+ args: Any,
592
+ kwargs: Any,
593
+ redirect: list | IOBase | None = None
594
+ ) -> T:
598
595
  """
599
596
  Redirect standard output.
600
597
 
601
598
  Parameters
602
599
  ----------
603
- func : Function to be decorated.
604
- args : Position arguments of decorated function.
605
- _redirect : Redirect output list or IO object.
606
- kwargs : Keyword arguments of decorated function.
600
+ func : Function.
601
+ args : Position arguments of function.
602
+ kwargs : Keyword arguments of function.
603
+ redirect : Redirect output list or IO object.
607
604
 
608
605
  Returns
609
606
  -------
610
- Function execution result.
607
+ Function return.
611
608
  """
612
609
 
613
610
  # Get parameter.
614
- if isinstance(_redirect, IOBase):
615
- str_io = _redirect
611
+ if isinstance(redirect, IOBase):
612
+ str_io = redirect
616
613
  else:
617
614
  str_io = StringIO()
618
615
 
@@ -621,8 +618,8 @@ def wrap_redirect_stdout(
621
618
  result = func(*args, **kwargs)
622
619
 
623
620
  # Save.
624
- if type(_redirect) == list:
621
+ if type(redirect) == list:
625
622
  value = str_io.getvalue()
626
- _redirect.append(value)
623
+ redirect.append(value)
627
624
 
628
625
  return result
reykit/rzip.py CHANGED
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reykit
3
- Version: 1.1.40
3
+ Version: 1.1.42
4
4
  Summary: Kit method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reykit/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -1,7 +1,7 @@
1
1
  reykit/__init__.py,sha256=V86CHqPAAVkooVx3_QIOKpDIFVneQCTTSwfJ-uWgBno,788
2
2
  reykit/rall.py,sha256=7Hip02YOkIDm3_xkoSDjvvYV2LhdBV2r4UKzWWnIfIo,628
3
- reykit/rbase.py,sha256=UBlu1-uOl3ZOeVIK6DvFbR3lZmthmGKjpbF-9vwQCpc,22116
4
- reykit/rdata.py,sha256=m30TX2O4dd6hNNdKdjdFv68s61tFu00pBoMVjqrFC5g,10309
3
+ reykit/rbase.py,sha256=KDiGiMwj-7u5sfGOPMEb4AgrWfJbUZqpFCYHIKs3O9w,22115
4
+ reykit/rdata.py,sha256=DqxoWkbN3WqGZ5FC9VRlhXAwpTGebv1M5VSeOeR2YnQ,10308
5
5
  reykit/remail.py,sha256=s7TXbLgEWEqNoeM42c6FpPufB2LajHgQuahfZri3urQ,6706
6
6
  reykit/rimage.py,sha256=p7caatLE71yy7GUTkTKyMOaJTeBfl6pZr_7BFjcDvY8,6159
7
7
  reykit/rlog.py,sha256=krjeLPptPiYgbXd9h4umx4Nf34Bt6jQBT0MEvatVKL4,25572
@@ -18,11 +18,11 @@ reykit/rtable.py,sha256=Ua6R1eHMtq4jAaWvfFTsgk-KQmtz5KwuYq4kguzRKaY,12198
18
18
  reykit/rtask.py,sha256=98iCzNdJ_fFRDyOLjXEFNW3tzdAwXcCF7JkZ7Gf0fEE,22848
19
19
  reykit/rtext.py,sha256=sFp5n5ykD6B812Bywhe6gqzscNmx-U6w80Zf8p1y-Ow,12859
20
20
  reykit/rtime.py,sha256=PfhsXZLmSsKY2W1A0VrjhaVbMKVBHBD86AZ8nowNGig,17008
21
- reykit/rwrap.py,sha256=RK3wlc2cd-lnAvzqzvKsS21EtCmBNTA3i8HRbaolWE4,15275
21
+ reykit/rwrap.py,sha256=3at29SGx5As9fmv1t9m_ibjHTvXpA6uPo-mroSsrX-I,15323
22
22
  reykit/rzip.py,sha256=ABUDLwEHQIpcvZbJE_oV78H7dik6nC7kaRz660Ro9Os,3481
23
23
  reykit/rdll/__init__.py,sha256=1VRawI2vCsLH7KK0PcBRWNc-bwseM-M05wkc_eamwJM,696
24
24
  reykit/rdll/rdll_core.py,sha256=o6-rKcTQgxZQe0kD3GnwyNb3KL9IogzgCQNOmYLMm7A,5086
25
- reykit-1.1.40.dist-info/METADATA,sha256=ygc-fWoLcUcugTfzuqCic7IFgOikwQocMEl3yJAqCUE,1872
26
- reykit-1.1.40.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- reykit-1.1.40.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
- reykit-1.1.40.dist-info/RECORD,,
25
+ reykit-1.1.42.dist-info/METADATA,sha256=Ed5D0QkQMK1JOdnTOo-TPq72aJm2bRVDmhgc0ImnlQE,1872
26
+ reykit-1.1.42.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ reykit-1.1.42.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
+ reykit-1.1.42.dist-info/RECORD,,