dycw-utilities 0.164.0__py3-none-any.whl → 0.164.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.164.0
3
+ Version: 0.164.1
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=cT3KdUJySCCzC99QlfI301hzQa3WEiHGbk_vNupSr98,60
1
+ utilities/__init__.py,sha256=MvCrVmUm07-n3CLSgsov6yvmEZo6n9Jy9H_ppTFtrsI,60
2
2
  utilities/aeventkit.py,sha256=ddoleSwW9zdc2tjX5Ge0pMKtYwV_JMxhHYOxnWX2AGM,12609
3
3
  utilities/altair.py,sha256=92E2lCdyHY4Zb-vCw6rEJIsWdKipuu-Tu2ab1ufUfAk,9079
4
4
  utilities/asyncio.py,sha256=PUedzQ5deqlSECQ33sam9cRzI9TnygHz3FdOqWJWPTM,15288
@@ -31,7 +31,7 @@ utilities/json.py,sha256=-WcGtSsCr9Y42wHZzAMnfvU6ihAfVftylFfRUORaDFo,2102
31
31
  utilities/jupyter.py,sha256=ft5JA7fBxXKzP-L9W8f2-wbF0QeYc_2uLQNFDVk4Z-M,2917
32
32
  utilities/libcst.py,sha256=TKgKN4bNmtBNEE-TUfhTyd1BrTncfsl_7tTuhpesGYY,5585
33
33
  utilities/lightweight_charts.py,sha256=YM3ojBvJxuCSUBu_KrhFBmaMCvRPvupKC3qkm-UVZq4,2751
34
- utilities/logging.py,sha256=uJ-hhtkrx4xnLUzZmE1soV4O8wQzNPUB1f_YJJe6I30,18089
34
+ utilities/logging.py,sha256=W3d8Vby0mmqGWvTNlGtcfrmORDTt7abCuqjkIyCPIg8,18914
35
35
  utilities/math.py,sha256=cevB-YyEYAzJTWtkAr7qeeu-hbxorDI3gMznXlmNQkw,26897
36
36
  utilities/memory_profiler.py,sha256=XzN56jDCa5aqXS_DxEjb_K4L6aIWh_5zyKi6OhcIxw0,853
37
37
  utilities/modules.py,sha256=iuvLluJya-hvl1Q25-Jk3dLgx2Es3ck4SjJiEkAlVTs,3195
@@ -76,7 +76,7 @@ utilities/timer.py,sha256=oXfTii6ymu57niP0BDGZjFD55LEHi2a19kqZKiTgaFQ,2588
76
76
  utilities/traceback.py,sha256=b1nSvlyrGmI1MyZLkkoLVET3DQBSGt9qqIlAAQbyjEw,9629
77
77
  utilities/typed_settings.py,sha256=SFWqS3lAzV7IfNRwqFcTk0YynTcQ7BmrcW2mr_KUnos,4466
78
78
  utilities/types.py,sha256=oeH-hEC3-67Eja4nLz-Nj9WvK6Z9-3T1zobO_XJpuVg,18735
79
- utilities/typing.py,sha256=UXhQPJ25sUawgYFIzH28NyuTje9ybg6tWDuN6BiU55E,24214
79
+ utilities/typing.py,sha256=vPqxHE2G5_dbDEgWAyAaTSDbUQE0pmihIj0vdXogbRU,24185
80
80
  utilities/tzdata.py,sha256=fgNVj66yUbCSI_-vrRVzSD3gtf-L_8IEJEPjP_Jel5Y,266
81
81
  utilities/tzlocal.py,sha256=KyCXEgCTjqGFx-389JdTuhMRUaT06U1RCMdWoED-qro,728
82
82
  utilities/uuid.py,sha256=nQZs6tFX4mqtc2Ku3KqjloYCqwpTKeTj8eKwQwh3FQI,1572
@@ -88,8 +88,8 @@ utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
88
88
  utilities/pytest_plugins/__init__.py,sha256=U4S_2y3zgLZVfMenHRaJFBW8yqh2mUBuI291LGQVOJ8,35
89
89
  utilities/pytest_plugins/pytest_randomly.py,sha256=B1qYVlExGOxTywq2r1SMi5o7btHLk2PNdY_b1p98dkE,409
90
90
  utilities/pytest_plugins/pytest_regressions.py,sha256=9v8kAXDM2ycIXJBimoiF4EgrwbUvxTycFWJiGR_GHhM,1466
91
- dycw_utilities-0.164.0.dist-info/METADATA,sha256=OTRhIzWSdVocu0RE1zn25hIns4nLsKu0TIBD8i2KdOs,1696
92
- dycw_utilities-0.164.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
- dycw_utilities-0.164.0.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
94
- dycw_utilities-0.164.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
- dycw_utilities-0.164.0.dist-info/RECORD,,
91
+ dycw_utilities-0.164.1.dist-info/METADATA,sha256=4-ckCdR3FFMcVm2AWHdzIEhR72r_NvE6YImrElaIkRY,1696
92
+ dycw_utilities-0.164.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
93
+ dycw_utilities-0.164.1.dist-info/entry_points.txt,sha256=BOD_SoDxwsfJYOLxhrSXhHP_T7iw-HXI9f2WVkzYxvQ,135
94
+ dycw_utilities-0.164.1.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
+ dycw_utilities-0.164.1.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.164.0"
3
+ __version__ = "0.164.1"
utilities/logging.py CHANGED
@@ -8,6 +8,7 @@ from logging import (
8
8
  Formatter,
9
9
  Handler,
10
10
  Logger,
11
+ LoggerAdapter,
11
12
  LogRecord,
12
13
  StreamHandler,
13
14
  basicConfig,
@@ -22,6 +23,7 @@ from socket import gethostname
22
23
  from typing import (
23
24
  TYPE_CHECKING,
24
25
  Any,
26
+ Concatenate,
25
27
  Literal,
26
28
  NotRequired,
27
29
  Self,
@@ -53,7 +55,7 @@ from utilities.whenever import (
53
55
  )
54
56
 
55
57
  if TYPE_CHECKING:
56
- from collections.abc import Iterable, Mapping
58
+ from collections.abc import Callable, Iterable, Mapping, MutableMapping
57
59
  from datetime import time
58
60
  from logging import _FilterType
59
61
 
@@ -63,6 +65,7 @@ if TYPE_CHECKING:
63
65
  MaybeCallablePathLike,
64
66
  MaybeIterable,
65
67
  PathLike,
68
+ StrMapping,
66
69
  )
67
70
 
68
71
 
@@ -75,6 +78,35 @@ _DEFAULT_WHEN: _When = "D"
75
78
  ##
76
79
 
77
80
 
81
+ def add_adapter[**P](
82
+ logger: Logger,
83
+ process: Callable[Concatenate[str, P], str],
84
+ /,
85
+ *args: P.args,
86
+ **kwargs: P.kwargs,
87
+ ) -> LoggerAdapter:
88
+ """Add an adapter to a logger."""
89
+
90
+ class CustomAdapter(LoggerAdapter):
91
+ @override
92
+ def process(
93
+ self, msg: str, kwargs: MutableMapping[str, Any]
94
+ ) -> tuple[str, MutableMapping[str, Any]]:
95
+ extra = cast("_ArgsAndKwargs", self.extra)
96
+ new_msg = process(msg, *extra["args"], **extra["kwargs"])
97
+ return new_msg, kwargs
98
+
99
+ return CustomAdapter(logger, extra=_ArgsAndKwargs(args=args, kwargs=kwargs))
100
+
101
+
102
+ class _ArgsAndKwargs(TypedDict):
103
+ args: tuple[Any, ...]
104
+ kwargs: StrMapping
105
+
106
+
107
+ ##
108
+
109
+
78
110
  def add_filters(handler: Handler, /, *filters: _FilterType) -> None:
79
111
  """Add a set of filters to a handler."""
80
112
  for filter_i in filters:
@@ -589,6 +621,7 @@ def to_logger(logger: LoggerLike | None = None, /) -> Logger:
589
621
  __all__ = [
590
622
  "GetLoggingLevelNumberError",
591
623
  "SizeAndTimeRotatingFileHandler",
624
+ "add_adapter",
592
625
  "add_filters",
593
626
  "basic_config",
594
627
  "get_format_str",
utilities/typing.py CHANGED
@@ -333,7 +333,7 @@ def is_instance_gen(
333
333
  warn_name_errors=warn_name_errors,
334
334
  )
335
335
  for t in type_
336
- ) # skipif-ci-and-not-windows
336
+ )
337
337
  if is_literal_type(type_):
338
338
  return obj in get_args(type_)
339
339
  if is_union_type(type_):