dycw-utilities 0.126.11__py3-none-any.whl → 0.126.12__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.
- {dycw_utilities-0.126.11.dist-info → dycw_utilities-0.126.12.dist-info}/METADATA +1 -1
- {dycw_utilities-0.126.11.dist-info → dycw_utilities-0.126.12.dist-info}/RECORD +7 -8
- utilities/__init__.py +1 -1
- utilities/reprlib.py +85 -1
- utilities/traceback.py +3 -5
- utilities/rich.py +0 -74
- {dycw_utilities-0.126.11.dist-info → dycw_utilities-0.126.12.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.126.11.dist-info → dycw_utilities-0.126.12.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
utilities/__init__.py,sha256=
|
1
|
+
utilities/__init__.py,sha256=w7Bw5b1ygtU74n1HhymesHdGAgm2zjsVhaI-oN62x8k,61
|
2
2
|
utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
|
3
3
|
utilities/asyncio.py,sha256=phbGti22VSe9cu-SwM1vP8kyUg8AUDHvvciMvE6JnCg,51842
|
4
4
|
utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
|
@@ -62,8 +62,7 @@ utilities/python_dotenv.py,sha256=iWcnpXbH7S6RoXHiLlGgyuH6udCupAcPd_gQ0eAenQ0,31
|
|
62
62
|
utilities/random.py,sha256=lYdjgxB7GCfU_fwFVl5U-BIM_HV3q6_urL9byjrwDM8,4157
|
63
63
|
utilities/re.py,sha256=5J4d8VwIPFVrX2Eb8zfoxImDv7IwiN_U7mJ07wR2Wvs,3958
|
64
64
|
utilities/redis.py,sha256=pMKJjNI5e0lG-FZh2_idMBBmfgNr53KIGjBquZQOLZc,37556
|
65
|
-
utilities/reprlib.py,sha256=
|
66
|
-
utilities/rich.py,sha256=t50MwwVBsoOLxzmeVFSVpjno4OW6Ufum32skXbV8-Bs,1911
|
65
|
+
utilities/reprlib.py,sha256=ssYTcBW-TeRh3fhCJv57sopTZHF5FrPyyUg9yp5XBlo,3953
|
67
66
|
utilities/scipy.py,sha256=X6ROnHwiUhAmPhM0jkfEh0-Fd9iRvwiqtCQMOLmOQF8,945
|
68
67
|
utilities/sentinel.py,sha256=3jIwgpMekWgDAxPDA_hXMP2St43cPhciKN3LWiZ7kv0,1248
|
69
68
|
utilities/shelve.py,sha256=HZsMwK4tcIfg3sh0gApx4-yjQnrY4o3V3ZRimvRhoW0,738
|
@@ -80,7 +79,7 @@ utilities/tenacity.py,sha256=1PUvODiBVgeqIh7G5TRt5WWMSqjLYkEqP53itT97WQc,4914
|
|
80
79
|
utilities/text.py,sha256=ymBFlP_cA8OgNnZRVNs7FAh7OG8HxE6YkiLEMZv5g_A,11297
|
81
80
|
utilities/threading.py,sha256=GvBOp4CyhHfN90wGXZuA2VKe9fGzMaEa7oCl4f3nnPU,1009
|
82
81
|
utilities/timer.py,sha256=Rkc49KSpHuC8s7vUxGO9DU55U9I6yDKnchsQqrUCVBs,4075
|
83
|
-
utilities/traceback.py,sha256=
|
82
|
+
utilities/traceback.py,sha256=Jg7HS3AwQ-W-msdwHp22_PSHZcR54PbmsSf115B6TSM,27435
|
84
83
|
utilities/types.py,sha256=2f1DqTZTMRlpCPWPd9-rh_uwmRPv9UdBoi_Bfv7Ccmo,18374
|
85
84
|
utilities/typing.py,sha256=H6ysJkI830aRwLsMKz0SZIw4cpcsm7d6KhQOwr-SDh0,13817
|
86
85
|
utilities/tzdata.py,sha256=yCf70NICwAeazN3_JcXhWvRqCy06XJNQ42j7r6gw3HY,1217
|
@@ -91,7 +90,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
|
|
91
90
|
utilities/whenever.py,sha256=jS31ZAY5OMxFxLja_Yo5Fidi87Pd-GoVZ7Vi_teqVDA,16743
|
92
91
|
utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
|
93
92
|
utilities/zoneinfo.py,sha256=-5j7IQ9nb7gR43rdgA7ms05im-XuqhAk9EJnQBXxCoQ,1874
|
94
|
-
dycw_utilities-0.126.
|
95
|
-
dycw_utilities-0.126.
|
96
|
-
dycw_utilities-0.126.
|
97
|
-
dycw_utilities-0.126.
|
93
|
+
dycw_utilities-0.126.12.dist-info/METADATA,sha256=T67klINutEoVWEiFhEoBupDjKUnBGBXokIa1or-nWfI,12804
|
94
|
+
dycw_utilities-0.126.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
95
|
+
dycw_utilities-0.126.12.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
|
96
|
+
dycw_utilities-0.126.12.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/reprlib.py
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import reprlib
|
4
|
-
from
|
4
|
+
from functools import partial
|
5
|
+
from typing import TYPE_CHECKING, Any
|
6
|
+
|
7
|
+
if TYPE_CHECKING:
|
8
|
+
from collections.abc import Iterator
|
9
|
+
|
10
|
+
from utilities.types import StrMapping
|
5
11
|
|
6
12
|
RICH_MAX_WIDTH: int = 80
|
7
13
|
RICH_INDENT_SIZE: int = 4
|
@@ -11,6 +17,19 @@ RICH_MAX_DEPTH: int | None = None
|
|
11
17
|
RICH_EXPAND_ALL: bool = False
|
12
18
|
|
13
19
|
|
20
|
+
##
|
21
|
+
|
22
|
+
|
23
|
+
def get_call_args_mapping(*args: Any, **kwargs: Any) -> StrMapping:
|
24
|
+
"""Get the representation of a set of call arguments."""
|
25
|
+
return {f"args[{i}]": v for i, v in enumerate(args)} | {
|
26
|
+
f"kwargs[{k}]": v for k, v in kwargs.items()
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
##
|
31
|
+
|
32
|
+
|
14
33
|
def get_repr(
|
15
34
|
obj: Any,
|
16
35
|
/,
|
@@ -38,6 +57,9 @@ def get_repr(
|
|
38
57
|
)
|
39
58
|
|
40
59
|
|
60
|
+
##
|
61
|
+
|
62
|
+
|
41
63
|
def get_repr_and_class(
|
42
64
|
obj: Any,
|
43
65
|
/,
|
@@ -62,6 +84,65 @@ def get_repr_and_class(
|
|
62
84
|
return f"Object {repr_use!r} of type {type(obj).__name__!r}"
|
63
85
|
|
64
86
|
|
87
|
+
##
|
88
|
+
|
89
|
+
|
90
|
+
def yield_call_args_repr(
|
91
|
+
*args: Any,
|
92
|
+
_max_width: int = RICH_MAX_WIDTH,
|
93
|
+
_indent_size: int = RICH_INDENT_SIZE,
|
94
|
+
_max_length: int | None = RICH_MAX_LENGTH,
|
95
|
+
_max_string: int | None = RICH_MAX_STRING,
|
96
|
+
_max_depth: int | None = RICH_MAX_DEPTH,
|
97
|
+
_expand_all: bool = RICH_EXPAND_ALL,
|
98
|
+
**kwargs: Any,
|
99
|
+
) -> Iterator[str]:
|
100
|
+
"""Pretty print of a set of positional/keyword arguments."""
|
101
|
+
mapping = get_call_args_mapping(*args, **kwargs)
|
102
|
+
return yield_mapping_repr(
|
103
|
+
mapping,
|
104
|
+
_max_width=_max_width,
|
105
|
+
_indent_size=_indent_size,
|
106
|
+
_max_length=_max_length,
|
107
|
+
_max_string=_max_string,
|
108
|
+
_max_depth=_max_depth,
|
109
|
+
_expand_all=_expand_all,
|
110
|
+
)
|
111
|
+
|
112
|
+
|
113
|
+
##
|
114
|
+
|
115
|
+
|
116
|
+
def yield_mapping_repr(
|
117
|
+
mapping: StrMapping,
|
118
|
+
/,
|
119
|
+
*,
|
120
|
+
_max_width: int = RICH_MAX_WIDTH,
|
121
|
+
_indent_size: int = RICH_INDENT_SIZE,
|
122
|
+
_max_length: int | None = RICH_MAX_LENGTH,
|
123
|
+
_max_string: int | None = RICH_MAX_STRING,
|
124
|
+
_max_depth: int | None = RICH_MAX_DEPTH,
|
125
|
+
_expand_all: bool = RICH_EXPAND_ALL,
|
126
|
+
) -> Iterator[str]:
|
127
|
+
"""Pretty print of a set of keyword arguments."""
|
128
|
+
try:
|
129
|
+
from rich.pretty import pretty_repr
|
130
|
+
except ModuleNotFoundError: # pragma: no cover
|
131
|
+
repr_use = repr
|
132
|
+
else:
|
133
|
+
repr_use = partial(
|
134
|
+
pretty_repr,
|
135
|
+
max_width=_max_width,
|
136
|
+
indent_size=_indent_size,
|
137
|
+
max_length=_max_length,
|
138
|
+
max_string=_max_string,
|
139
|
+
max_depth=_max_depth,
|
140
|
+
expand_all=_expand_all,
|
141
|
+
)
|
142
|
+
for k, v in mapping.items():
|
143
|
+
yield f"{k} = {repr_use(v)}"
|
144
|
+
|
145
|
+
|
65
146
|
__all__ = [
|
66
147
|
"RICH_EXPAND_ALL",
|
67
148
|
"RICH_INDENT_SIZE",
|
@@ -69,6 +150,9 @@ __all__ = [
|
|
69
150
|
"RICH_MAX_LENGTH",
|
70
151
|
"RICH_MAX_STRING",
|
71
152
|
"RICH_MAX_WIDTH",
|
153
|
+
"get_call_args_mapping",
|
72
154
|
"get_repr",
|
73
155
|
"get_repr_and_class",
|
156
|
+
"yield_call_args_repr",
|
157
|
+
"yield_mapping_repr",
|
74
158
|
]
|
utilities/traceback.py
CHANGED
@@ -42,6 +42,8 @@ from utilities.reprlib import (
|
|
42
42
|
RICH_MAX_LENGTH,
|
43
43
|
RICH_MAX_STRING,
|
44
44
|
RICH_MAX_WIDTH,
|
45
|
+
yield_call_args_repr,
|
46
|
+
yield_mapping_repr,
|
45
47
|
)
|
46
48
|
from utilities.types import TBaseException, TCallable
|
47
49
|
from utilities.version import get_version
|
@@ -199,8 +201,6 @@ class _CallArgs:
|
|
199
201
|
@classmethod
|
200
202
|
def create(cls, func: Callable[..., Any], *args: Any, **kwargs: Any) -> Self:
|
201
203
|
"""Make the initial trace data."""
|
202
|
-
from utilities.rich import yield_call_args_repr
|
203
|
-
|
204
204
|
sig = signature(func)
|
205
205
|
try:
|
206
206
|
bound_args = sig.bind(*args, **kwargs)
|
@@ -437,8 +437,6 @@ class _Frame:
|
|
437
437
|
depth: int = 0,
|
438
438
|
) -> str:
|
439
439
|
"""Format the traceback."""
|
440
|
-
from utilities.rich import yield_call_args_repr, yield_mapping_repr
|
441
|
-
|
442
440
|
lines: list[str] = [f"Frame {index + 1}/{total}: {self.name} ({self.module})"]
|
443
441
|
if detail:
|
444
442
|
lines.append(indent("Inputs:", _INDENT))
|
@@ -459,13 +457,13 @@ class _Frame:
|
|
459
457
|
lines.extend(
|
460
458
|
indent(line, 2 * _INDENT)
|
461
459
|
for line in yield_mapping_repr(
|
460
|
+
self.locals,
|
462
461
|
_max_width=self.max_width,
|
463
462
|
_indent_size=self.indent_size,
|
464
463
|
_max_length=self.max_length,
|
465
464
|
_max_string=self.max_string,
|
466
465
|
_max_depth=self.max_depth,
|
467
466
|
_expand_all=self.expand_all,
|
468
|
-
**self.locals,
|
469
467
|
)
|
470
468
|
)
|
471
469
|
lines.extend([
|
utilities/rich.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from typing import TYPE_CHECKING, Any
|
4
|
-
|
5
|
-
from rich.pretty import pretty_repr
|
6
|
-
|
7
|
-
from utilities.reprlib import (
|
8
|
-
RICH_EXPAND_ALL,
|
9
|
-
RICH_INDENT_SIZE,
|
10
|
-
RICH_MAX_DEPTH,
|
11
|
-
RICH_MAX_LENGTH,
|
12
|
-
RICH_MAX_STRING,
|
13
|
-
RICH_MAX_WIDTH,
|
14
|
-
)
|
15
|
-
|
16
|
-
if TYPE_CHECKING:
|
17
|
-
from collections.abc import Iterator
|
18
|
-
|
19
|
-
|
20
|
-
##
|
21
|
-
|
22
|
-
|
23
|
-
def yield_call_args_repr(
|
24
|
-
*args: Any,
|
25
|
-
_max_width: int = RICH_MAX_WIDTH,
|
26
|
-
_indent_size: int = RICH_INDENT_SIZE,
|
27
|
-
_max_length: int | None = RICH_MAX_LENGTH,
|
28
|
-
_max_string: int | None = RICH_MAX_STRING,
|
29
|
-
_max_depth: int | None = RICH_MAX_DEPTH,
|
30
|
-
_expand_all: bool = RICH_EXPAND_ALL,
|
31
|
-
**kwargs: Any,
|
32
|
-
) -> Iterator[str]:
|
33
|
-
"""Pretty print of a set of positional/keyword arguments."""
|
34
|
-
mapping = {f"args[{i}]": v for i, v in enumerate(args)} | {
|
35
|
-
f"kwargs[{k}]": v for k, v in kwargs.items()
|
36
|
-
}
|
37
|
-
return yield_mapping_repr(
|
38
|
-
_max_width=_max_width,
|
39
|
-
_indent_size=_indent_size,
|
40
|
-
_max_length=_max_length,
|
41
|
-
_max_string=_max_string,
|
42
|
-
_max_depth=_max_depth,
|
43
|
-
_expand_all=_expand_all,
|
44
|
-
**mapping,
|
45
|
-
)
|
46
|
-
|
47
|
-
|
48
|
-
##
|
49
|
-
|
50
|
-
|
51
|
-
def yield_mapping_repr(
|
52
|
-
_max_width: int = RICH_MAX_WIDTH,
|
53
|
-
_indent_size: int = RICH_INDENT_SIZE,
|
54
|
-
_max_length: int | None = RICH_MAX_LENGTH,
|
55
|
-
_max_string: int | None = RICH_MAX_STRING,
|
56
|
-
_max_depth: int | None = RICH_MAX_DEPTH,
|
57
|
-
_expand_all: bool = RICH_EXPAND_ALL, # noqa: FBT001
|
58
|
-
**kwargs: Any,
|
59
|
-
) -> Iterator[str]:
|
60
|
-
"""Pretty print of a set of keyword arguments."""
|
61
|
-
for k, v in kwargs.items():
|
62
|
-
v_repr = pretty_repr(
|
63
|
-
v,
|
64
|
-
max_width=_max_width,
|
65
|
-
indent_size=_indent_size,
|
66
|
-
max_length=_max_length,
|
67
|
-
max_string=_max_string,
|
68
|
-
max_depth=_max_depth,
|
69
|
-
expand_all=_expand_all,
|
70
|
-
)
|
71
|
-
yield f"{k} = {v_repr}"
|
72
|
-
|
73
|
-
|
74
|
-
__all__ = ["yield_call_args_repr", "yield_mapping_repr"]
|
File without changes
|
File without changes
|