turbo-lambda 0.7.0__tar.gz → 0.8.0__tar.gz

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,12 +1,12 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: turbo-lambda
3
- Version: 0.7.0
3
+ Version: 0.8.0
4
4
  Summary: Turbo Lambda Description
5
5
  Author: Sam Mosleh
6
6
  Author-email: Sam Mosleh <sam.mosleh.d@gmail.com>
7
7
  Requires-Dist: opentelemetry-api>=1.27.0
8
8
  Requires-Dist: pydantic-settings>=2.11.0
9
- Requires-Python: >=3.12
9
+ Requires-Python: >=3.14
10
10
  Description-Content-Type: text/markdown
11
11
 
12
12
  # turbo-lambda
@@ -1,10 +1,10 @@
1
1
  [project]
2
2
  name = "turbo-lambda"
3
- version = "0.7.0"
3
+ version = "0.8.0"
4
4
  description = "Turbo Lambda Description"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Sam Mosleh", email = "sam.mosleh.d@gmail.com" }]
7
- requires-python = ">=3.12"
7
+ requires-python = ">=3.14"
8
8
  dependencies = [
9
9
  "opentelemetry-api>=1.27.0",
10
10
  "pydantic-settings>=2.11.0",
@@ -126,6 +126,7 @@ def request_logger_handler[ResponseT](
126
126
  log_level=logging.DEBUG,
127
127
  log_message="request",
128
128
  log_exceptions=True,
129
+ excluded_fields=("context",),
129
130
  )
130
131
  @wraps(func)
131
132
  def handler(
@@ -166,6 +167,7 @@ def gateway_handler[RequestT: pydantic.BaseModel](
166
167
  log_level=logging.DEBUG,
167
168
  log_message="request",
168
169
  log_exceptions=True,
170
+ excluded_fields=("context",),
169
171
  result_extractor=result_extractor,
170
172
  )
171
173
  @error_transformer_handler(general_error_to_gateway_response)
@@ -1,10 +1,13 @@
1
+ import annotationlib
1
2
  import contextlib
2
3
  import contextvars
3
4
  import datetime
4
5
  import inspect
5
6
  import logging
6
7
  import time
8
+ import uuid
7
9
  from collections.abc import Callable, Generator, Iterable
10
+ from enum import Enum
8
11
  from functools import wraps
9
12
  from typing import Any, overload
10
13
 
@@ -38,6 +41,8 @@ def _json_custom_default(value: Any) -> Any:
38
41
  return value.model_dump(mode="json")
39
42
  case datetime.datetime() | datetime.date():
40
43
  return value.isoformat()
44
+ case uuid.UUID() | Enum():
45
+ return str(value)
41
46
  case set():
42
47
  return list(value)
43
48
  case _:
@@ -53,6 +58,10 @@ def _setup_logger() -> None: # pragma: no cover
53
58
  lambda_runtime_log_utils._json_encoder.default = _json_custom_default
54
59
 
55
60
 
61
+ def _default_result_extractor[T](res: T) -> dict[str, T]:
62
+ return {"result": res}
63
+
64
+
56
65
  @overload
57
66
  def log_after_call[**P, T](func: Callable[P, T]) -> Callable[P, T]: ...
58
67
 
@@ -63,8 +72,8 @@ def log_after_call[**P, T](
63
72
  log_level: int = logging.INFO,
64
73
  log_message: str = "call",
65
74
  log_exceptions: bool = False,
66
- excluded_fields: Iterable[str] = ("self", "context"),
67
- result_extractor: None = None,
75
+ excluded_fields: Iterable[str] = ("self",),
76
+ result_extractor: bool = False,
68
77
  ) -> Callable[[Callable[P, T]], Callable[P, T]]: ...
69
78
 
70
79
 
@@ -74,7 +83,7 @@ def log_after_call[**P, T](
74
83
  log_level: int = logging.INFO,
75
84
  log_message: str = "call",
76
85
  log_exceptions: bool = False,
77
- excluded_fields: Iterable[str] = ("self", "context"),
86
+ excluded_fields: Iterable[str] = ("self",),
78
87
  result_extractor: Callable[[T], dict[str, Any]],
79
88
  ) -> Callable[[Callable[P, T]], Callable[P, T]]: ...
80
89
 
@@ -84,11 +93,18 @@ def log_after_call[**P, T]( # noqa: PLR0913
84
93
  log_level: int = logging.INFO,
85
94
  log_message: str = "call",
86
95
  log_exceptions: bool = False,
87
- excluded_fields: Iterable[str] = ("self", "context"),
88
- result_extractor: Callable[[T], dict[str, Any]] | None = None,
96
+ excluded_fields: Iterable[str] = ("self",),
97
+ result_extractor: Callable[[T], dict[str, Any]] | bool = False,
89
98
  ) -> Callable[P, T] | Callable[[Callable[P, T]], Callable[P, T]]:
90
99
  def decorator(func: Callable[P, T]) -> Callable[P, T]:
91
- sig = inspect.signature(func)
100
+ sig = inspect.signature(func, annotation_format=annotationlib.Format.STRING)
101
+ result_extractor_func = (
102
+ result_extractor
103
+ if callable(result_extractor)
104
+ else _default_result_extractor
105
+ if result_extractor
106
+ else None
107
+ )
92
108
 
93
109
  @wraps(func)
94
110
  def wrapper(*f_args: P.args, **f_kwargs: P.kwargs) -> T:
@@ -106,8 +122,8 @@ def log_after_call[**P, T]( # noqa: PLR0913
106
122
  st = time.monotonic()
107
123
  try:
108
124
  result = func(*f_args, **f_kwargs)
109
- if result_extractor:
110
- extra.update(result_extractor(result))
125
+ if result_extractor_func:
126
+ extra.update(result_extractor_func(result))
111
127
  return result
112
128
  except Exception as e:
113
129
  if log_exceptions:
File without changes