Static type checker used
mypy (project's standard)
AWS Lambda function runtime
3.13
Powertools for AWS Lambda (Python) version
latest
Static type checker info
Docstring is correct, the underlying provider.set_timestamp() is correct as well, but Metrics.set_timestamp() only allows and int argument.
$ uvx --with aws_lambda_powertools mypy test.py
test.py:7:25: error: Argument 1 to "set_timestamp" of "Metrics" has incompatible type "datetime"; expected "int" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Code snippet
from datetime import UTC, datetime
from aws_lambda_powertools import Metrics
now = datetime.now(UTC)
Metrics().set_timestamp(int(now.timestamp() * 1_000)) # ok
Metrics().set_timestamp(now) # incompatible type
Metrics().provider.set_timestamp(int(now.timestamp() * 1_000)) # ok
Metrics().provider.set_timestamp(now) # ok
Possible Solution
Add datetime.datetime as a possible type to Metrics.set_timestamp(timestamp: int).
Static type checker used
mypy (project's standard)
AWS Lambda function runtime
3.13
Powertools for AWS Lambda (Python) version
latest
Static type checker info
Docstring is correct, the underlying
provider.set_timestamp()is correct as well, butMetrics.set_timestamp()only allows andintargument.Code snippet
Possible Solution
Add
datetime.datetimeas a possible type toMetrics.set_timestamp(timestamp: int).