Skip to content

revert(metrics): typing regression on log_metrics callable #744

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Conversation

heitorlessa
Copy link
Contributor

Issue #, if available: #743

Description of changes:

Fixes a typing regression for log_metrics where the return had an explicit Callable and this confuses MyPy and loses the param spec.

from aws_lambda_powertools import Metrics
from aws_lambda_powertools.utilities.typing import LambdaContext

metrics = Metrics(namespace="test")


@metrics.log_metrics
def lambda_handler(evt: dict, ctx: LambdaContext):
    metrics.add_metric(name="test", unit="Count", value=1)

Error

$ mypy ~/Library/Application\ Support/JetBrains/PyCharm2021.2/scratches/scratch.py
/Users/lessa/Library/Application Support/JetBrains/PyCharm2021.2/scratches/scratch.py:11:1: error: <nothing> not callable  [misc]
/Users/lessa/Library/Application Support/JetBrains/PyCharm2021.2/scratches/scratch.py:12:1: error: <nothing> not callable  [misc]
Found 2 errors in 1 file (checked 1 source file)

Checklist

Breaking change checklist

RFC issue #:

  • Migration process documented
  • Implement warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 7, 2021
@heitorlessa heitorlessa added the bug Something isn't working label Oct 7, 2021
@codecov-commenter
Copy link

codecov-commenter commented Oct 7, 2021

Codecov Report

Merging #744 (9b0ba28) into develop (97c9423) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #744      +/-   ##
===========================================
- Coverage    99.77%   99.77%   -0.01%     
===========================================
  Files          117      117              
  Lines         4922     4921       -1     
  Branches       271      271              
===========================================
- Hits          4911     4910       -1     
  Misses           9        9              
  Partials         2        2              
Impacted Files Coverage Δ
aws_lambda_powertools/metrics/metrics.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 989a4f6...9b0ba28. Read the comment docs.

@heitorlessa heitorlessa linked an issue Oct 7, 2021 that may be closed by this pull request
@heitorlessa heitorlessa merged commit c999f40 into aws-powertools:develop Oct 7, 2021
@heitorlessa heitorlessa deleted the fix/metrics-log-metrics-typing branch October 7, 2021 11:21
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MyPy error on @metrics.log_metrics(capture_cold_start_metric=True)
2 participants