Skip to content

Commit 1951574

Browse files
author
Michael Brewer
authored
chore: fix typos, docstrings and type hints (#154)
Changes: * Fix some of the type hints * Add missing docstrings for parameters * Fix typos
1 parent b28c47e commit 1951574

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# We use poetry to run formatting and linting before commit/push
2-
# Longers checks such as tests, security and complexity baseline
2+
# Longer checks such as tests, security and complexity baseline
33
# are run as part of CI to prevent slower feedback loop
44
# All checks can be run locally via `make pr`
55

aws_lambda_powertools/metrics/base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def add_metric(self, name: str, unit: MetricUnit, value: Union[float, int]):
112112
Metric name
113113
unit : MetricUnit
114114
`aws_lambda_powertools.helper.models.MetricUnit`
115-
value : float
115+
value : Union[float, int]
116116
Metric value
117117
118118
Raises
@@ -146,6 +146,8 @@ def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, me
146146
Dictionary of metrics to serialize, by default None
147147
dimensions : Dict, optional
148148
Dictionary of dimensions to serialize, by default None
149+
metadata: Dict, optional
150+
Dictionary of metadata to serialize, by default None
149151
150152
Example
151153
-------
@@ -183,7 +185,7 @@ def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, me
183185
metric_names_and_values: Dict[str, str] = {} # { "metric_name": 1.0 }
184186

185187
for metric_name in metrics:
186-
metric: str = metrics[metric_name]
188+
metric: dict = metrics[metric_name]
187189
metric_value: int = metric.get("Value", 0)
188190
metric_unit: str = metric.get("Unit", "")
189191

@@ -257,7 +259,7 @@ def add_metadata(self, key: str, value: Any):
257259
258260
Parameters
259261
----------
260-
name : str
262+
key : str
261263
Metadata key
262264
value : any
263265
Metadata value

aws_lambda_powertools/utilities/batch/sqs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, config: Optional[Config] = None):
5555

5656
super().__init__()
5757

58-
def _get_queue_url(self) -> str:
58+
def _get_queue_url(self) -> Optional[str]:
5959
"""
6060
Format QueueUrl from first records entry
6161
"""

docs/content/utilities/batch.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SQS integration with Lambda is one of the most well established ones and pretty
2828

2929
As any function call, you may face errors during execution, in one or more records belonging to a batch. SQS's native behavior is to redrive the **whole** batch to the queue again, reprocessing all of them again, including successful ones. This cycle can happen multiple times depending on your [configuration][3], until the whole batch succeeds or the maximum number of attempts is reached. Your application may face some problems with such behavior, especially if there's no idempotency.
3030

31-
A *naive* approach to solving this problem is to delete successful records from the queue before redriving's phase. The `PartialSQSProcessor` class offers this solution both as context manager and middleware, removing all successful messages from the queue case one or more failures ocurred during lambda's execution. Two examples are provided below, displaying the behavior of this class.
31+
A *naive* approach to solving this problem is to delete successful records from the queue before redriving's phase. The `PartialSQSProcessor` class offers this solution both as context manager and middleware, removing all successful messages from the queue case one or more failures occurred during lambda's execution. Two examples are provided below, displaying the behavior of this class.
3232

3333
**Examples:**
3434

example/hello_world/app.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
set_package_logger() # Enable package diagnostics (DEBUG log)
1515

1616
# tracer = Tracer() # patches all available modules # noqa: E800
17-
tracer = Tracer(patch_modules=("aioboto3", "boto3", "requests")) # ~90-100ms faster in perf depending on set of libs
17+
tracer = Tracer(patch_modules=["aioboto3", "boto3", "requests"]) # ~90-100ms faster in perf depending on set of libs
1818
logger = Logger()
1919
metrics = Metrics()
2020

@@ -114,13 +114,13 @@ def lambda_handler(event, context):
114114

115115
try:
116116
ip = requests.get("http://checkip.amazonaws.com/")
117-
metrics.add_metric(name="SuccessfulLocations", unit="Count", value=1)
117+
metrics.add_metric(name="SuccessfulLocations", unit=MetricUnit.Count, value=1)
118118
except requests.RequestException as e:
119119
# Send some context about this error to Lambda Logs
120120
logger.exception(e)
121121
raise
122122

123-
with single_metric(name="UniqueMetricDimension", unit="Seconds", value=1) as metric:
123+
with single_metric(name="UniqueMetricDimension", unit=MetricUnit.Seconds, value=1) as metric:
124124
metric.add_dimension(name="unique_dimension", value="for_unique_metric")
125125

126126
resp = {"message": "hello world", "location": ip.text.replace("\n", ""), "async_http": async_http_ret}

0 commit comments

Comments
 (0)