stouputils 1.18.3__py3-none-any.whl → 1.18.4__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.
- stouputils/decorators.py +35 -11
- stouputils/decorators.pyi +7 -0
- {stouputils-1.18.3.dist-info → stouputils-1.18.4.dist-info}/METADATA +1 -1
- {stouputils-1.18.3.dist-info → stouputils-1.18.4.dist-info}/RECORD +6 -6
- {stouputils-1.18.3.dist-info → stouputils-1.18.4.dist-info}/WHEEL +0 -0
- {stouputils-1.18.3.dist-info → stouputils-1.18.4.dist-info}/entry_points.txt +0 -0
stouputils/decorators.py
CHANGED
|
@@ -76,7 +76,7 @@ def measure_time(
|
|
|
76
76
|
def wrapper(*args: tuple[Any, ...], **kwargs: dict[str, Any]) -> Any:
|
|
77
77
|
with MeasureTime(print_func=printer, message=new_msg, perf_counter=perf_counter):
|
|
78
78
|
return func(*args, **kwargs)
|
|
79
|
-
wrapper
|
|
79
|
+
_set_wrapper_name(wrapper, _get_wrapper_name("stouputils.decorators.measure_time", func))
|
|
80
80
|
return wrapper
|
|
81
81
|
|
|
82
82
|
# Handle both @measure_time and @measure_time(printer=..., message=..., perf_counter=..., is_generator=...)
|
|
@@ -160,7 +160,7 @@ def handle_error(
|
|
|
160
160
|
# Sleep for the specified time, only if the error_log is not ERROR_TRACEBACK (because it's blocking)
|
|
161
161
|
if sleep_time > 0.0 and error_log != LogLevels.ERROR_TRACEBACK:
|
|
162
162
|
time.sleep(sleep_time)
|
|
163
|
-
wrapper
|
|
163
|
+
_set_wrapper_name(wrapper, _get_wrapper_name("stouputils.decorators.handle_error", func))
|
|
164
164
|
return wrapper
|
|
165
165
|
|
|
166
166
|
# Handle both @handle_error and @handle_error(exceptions=..., message=..., error_log=...)
|
|
@@ -277,7 +277,7 @@ def timeout(
|
|
|
277
277
|
if result_container:
|
|
278
278
|
return result_container[0]
|
|
279
279
|
|
|
280
|
-
wrapper
|
|
280
|
+
_set_wrapper_name(wrapper, _get_wrapper_name("stouputils.decorators.timeout", func))
|
|
281
281
|
return wrapper
|
|
282
282
|
|
|
283
283
|
# Handle both @timeout and @timeout(seconds=..., message=...)
|
|
@@ -352,7 +352,7 @@ def retry(
|
|
|
352
352
|
time.sleep(current_delay)
|
|
353
353
|
current_delay *= backoff
|
|
354
354
|
|
|
355
|
-
wrapper
|
|
355
|
+
_set_wrapper_name(wrapper, _get_wrapper_name("stouputils.decorators.retry", func))
|
|
356
356
|
return wrapper
|
|
357
357
|
|
|
358
358
|
# Handle both @retry and @retry(exceptions=..., max_attempts=..., delay=...)
|
|
@@ -427,7 +427,7 @@ def simple_cache(
|
|
|
427
427
|
return result
|
|
428
428
|
|
|
429
429
|
# Return the wrapper
|
|
430
|
-
wrapper
|
|
430
|
+
_set_wrapper_name(wrapper, _get_wrapper_name("stouputils.decorators.simple_cache", func))
|
|
431
431
|
return wrapper
|
|
432
432
|
|
|
433
433
|
# Handle both @simple_cache and @simple_cache(method=...)
|
|
@@ -477,10 +477,10 @@ def abstract(
|
|
|
477
477
|
|
|
478
478
|
@wraps(func)
|
|
479
479
|
@handle_error(exceptions=NotImplementedError, error_log=error_log)
|
|
480
|
-
def
|
|
480
|
+
def not_implemented_error(*args: tuple[Any, ...], **kwargs: dict[str, Any]) -> Any:
|
|
481
481
|
raise NotImplementedError(message)
|
|
482
|
-
|
|
483
|
-
return
|
|
482
|
+
_set_wrapper_name(not_implemented_error, _get_wrapper_name("stouputils.decorators.abstract", func))
|
|
483
|
+
return not_implemented_error
|
|
484
484
|
|
|
485
485
|
# Handle both @abstract and @abstract(error_log=...)
|
|
486
486
|
if func is None:
|
|
@@ -541,7 +541,7 @@ def deprecated(
|
|
|
541
541
|
|
|
542
542
|
# Call the original function
|
|
543
543
|
return func(*args, **kwargs)
|
|
544
|
-
wrapper
|
|
544
|
+
_set_wrapper_name(wrapper, _get_wrapper_name("stouputils.decorators.deprecated", func))
|
|
545
545
|
return wrapper
|
|
546
546
|
|
|
547
547
|
# Handle both @deprecated and @deprecated(message=..., error_log=...)
|
|
@@ -582,7 +582,7 @@ def silent(
|
|
|
582
582
|
# Use Muffle context manager to silence output
|
|
583
583
|
with Muffle(mute_stderr=mute_stderr):
|
|
584
584
|
return func(*args, **kwargs)
|
|
585
|
-
wrapper
|
|
585
|
+
_set_wrapper_name(wrapper, _get_wrapper_name("stouputils.decorators.silent", func))
|
|
586
586
|
return wrapper
|
|
587
587
|
|
|
588
588
|
# Handle both @silent and @silent(mute_stderr=...)
|
|
@@ -613,7 +613,31 @@ def _get_wrapper_name(decorator_name: str, func: Callable[..., Any]) -> str:
|
|
|
613
613
|
|
|
614
614
|
# Remove "stouputils.decorators.*" prefix if present
|
|
615
615
|
if func_name.startswith("stouputils.decorators."):
|
|
616
|
-
func_name =
|
|
616
|
+
func_name = func_name.split(".", 2)[-1]
|
|
617
617
|
|
|
618
618
|
return f"{decorator_name}@{func_name}"
|
|
619
619
|
|
|
620
|
+
|
|
621
|
+
def _set_wrapper_name(wrapper: Callable[..., Any], name: str) -> None:
|
|
622
|
+
""" Set the wrapper function's visible name, qualname and code object name for clearer tracebacks.
|
|
623
|
+
|
|
624
|
+
Args:
|
|
625
|
+
wrapper (Callable[..., Any]): Wrapper function to update
|
|
626
|
+
name (str): New name to set
|
|
627
|
+
"""
|
|
628
|
+
# __name__ affects repr and some introspection
|
|
629
|
+
wrapper.__name__ = name
|
|
630
|
+
|
|
631
|
+
# __qualname__ helps when using nested scopes and in some introspection tools
|
|
632
|
+
try:
|
|
633
|
+
wrapper.__qualname__ = name
|
|
634
|
+
except Exception:
|
|
635
|
+
pass
|
|
636
|
+
|
|
637
|
+
# Update the code object's co_name so tracebacks show the new name
|
|
638
|
+
try:
|
|
639
|
+
wrapper.__code__ = wrapper.__code__.replace(co_name=name)
|
|
640
|
+
except Exception:
|
|
641
|
+
# If code.replace isn't available, ignore silently
|
|
642
|
+
pass
|
|
643
|
+
|
stouputils/decorators.pyi
CHANGED
|
@@ -250,3 +250,10 @@ def _get_wrapper_name(decorator_name: str, func: Callable[..., Any]) -> str:
|
|
|
250
250
|
\tReturns:
|
|
251
251
|
\t\tstr: Combined name for the wrapper function (e.g., "stouputils.decorators.handle_error@function_name")
|
|
252
252
|
\t'''
|
|
253
|
+
def _set_wrapper_name(wrapper: Callable[..., Any], name: str) -> None:
|
|
254
|
+
""" Set the wrapper function's visible name, qualname and code object name for clearer tracebacks.
|
|
255
|
+
|
|
256
|
+
\tArgs:
|
|
257
|
+
\t\twrapper\t(Callable[..., Any]):\tWrapper function to update
|
|
258
|
+
\t\tname\t(str):\t\t\t\t\tNew name to set
|
|
259
|
+
\t"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: stouputils
|
|
3
|
-
Version: 1.18.
|
|
3
|
+
Version: 1.18.4
|
|
4
4
|
Summary: Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more.
|
|
5
5
|
Keywords: utilities,tools,helpers,development,python
|
|
6
6
|
Author: Stoupy51
|
|
@@ -109,8 +109,8 @@ stouputils/data_science/scripts/exhaustive_process.py,sha256=Dc5gceIlIiP8U0m1qt3
|
|
|
109
109
|
stouputils/data_science/scripts/preprocess_dataset.py,sha256=OLC2KjEtSMeyHHPpNOATfNDuq0lZ09utKhsuzBA4MN4,2929
|
|
110
110
|
stouputils/data_science/scripts/routine.py,sha256=FkTLzmcdm_qUp69D-dPAKJm2RfXZZLtPgje6lEopu2I,7662
|
|
111
111
|
stouputils/data_science/utils.py,sha256=HFXI2RQZ53RbBOn_4Act2bi0z4xQlTtsuR5Am80v9JU,11084
|
|
112
|
-
stouputils/decorators.py,sha256=
|
|
113
|
-
stouputils/decorators.pyi,sha256=
|
|
112
|
+
stouputils/decorators.py,sha256=n09JOhE7WamBuD1bmRPI4dBezZuAyP9-s34C_MfvlCs,22677
|
|
113
|
+
stouputils/decorators.pyi,sha256=cFPYyQOR6hFq2sOmDXjT9Ozfl2UcU1avPwbd5ffL6ho,11249
|
|
114
114
|
stouputils/image.py,sha256=E6RYfLhE19KGxn9VdgPCTYXVmOUNK8Qe3RrwSp9OiPs,16479
|
|
115
115
|
stouputils/image.pyi,sha256=bGbNTG4piQ2PCLFqZCE360O8yE635cKX94SGK0aHNJ8,8311
|
|
116
116
|
stouputils/installer/__init__.py,sha256=DBwI9w3xvw0NR_jDMxmURwPi1F79kPLe7EuNjmrxW_U,502
|
|
@@ -156,7 +156,7 @@ stouputils/typing.py,sha256=TwvxrvxhBRkyHkoOpfyXebN13M3xJb8MAjKXiNIWjew,2205
|
|
|
156
156
|
stouputils/typing.pyi,sha256=U2UmFZausMYpnsUQROQE2JOwHcjx2hKV0rJuOdR57Ew,1341
|
|
157
157
|
stouputils/version_pkg.py,sha256=Jsp-s03L14DkiZ94vQgrlQmaxApfn9DC8M_nzT1SJLk,7014
|
|
158
158
|
stouputils/version_pkg.pyi,sha256=QPvqp1U3QA-9C_CC1dT9Vahv1hXEhstbM7x5uzMZSsQ,755
|
|
159
|
-
stouputils-1.18.
|
|
160
|
-
stouputils-1.18.
|
|
161
|
-
stouputils-1.18.
|
|
162
|
-
stouputils-1.18.
|
|
159
|
+
stouputils-1.18.4.dist-info/WHEEL,sha256=e_m4S054HL0hyR3CpOk-b7Q7fDX6BuFkgL5OjAExXas,80
|
|
160
|
+
stouputils-1.18.4.dist-info/entry_points.txt,sha256=tx0z9VOnE-sfkmbFbA93zaBMzV3XSsKEJa_BWIqUzxw,57
|
|
161
|
+
stouputils-1.18.4.dist-info/METADATA,sha256=4VyZ0zxM9F5r4C1No_8NCtX6LOgUgU0rQrR2XrA0zkU,14011
|
|
162
|
+
stouputils-1.18.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|