Skip to content

fix(metrics): explicit type to single_metric ctx manager - #865

Merged
heitorlessa merged 2 commits into
aws-powertools:developfrom
whardier:fix/metrics-add-typing-to-single-metric
Dec 8, 2021
Merged

fix(metrics): explicit type to single_metric ctx manager#865
heitorlessa merged 2 commits into
aws-powertools:developfrom
whardier:fix/metrics-add-typing-to-single-metric

Conversation

@whardier

@whardier whardier commented Dec 2, 2021

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

Simply update type return for metrics.metric.single_metric.

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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Dec 2, 2021
@codecov-commenter

codecov-commenter commented Dec 2, 2021

Copy link
Copy Markdown

Codecov Report

Merging #865 (de51add) into develop (8cfa773) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           develop     #865    +/-   ##
=========================================
  Coverage    99.90%   99.90%            
=========================================
  Files          118      118            
  Lines         5125     5126     +1     
  Branches       283      571   +288     
=========================================
+ Hits          5120     5121     +1     
  Misses           2        2            
  Partials         3        3            
Impacted Files Coverage Δ
aws_lambda_powertools/metrics/metric.py 100.00% <100.00%> (ø)
...wertools/utilities/idempotency/persistence/base.py 99.37% <0.00%> (+<0.01%) ⬆️

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 8cfa773...de51add. Read the comment docs.

@heitorlessa heitorlessa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change to use Generator[SingleMetric, None, None] due to a new issue discovered in Python typeshed when using Iterator[] in this context.

Comment thread aws_lambda_powertools/metrics/metric.py Outdated
Comment thread aws_lambda_powertools/metrics/metric.py Outdated
@heitorlessa

Copy link
Copy Markdown
Contributor

I created a new project using VSCode and PyLance and I couldn't reproduce this issue, same with PyCharm so perhaps their InteliSense is smart by inspecting the yield type SingleMetric.

Nevertheless, TIL why we can't use Iterator[SingleMetric] and instead should use Generator[SingleMetric, None, None.

For the sake of correctness regardless of what IDE one might use, I'm gonna commit the Generator suggestion to avoid issues and merge it.

@heitorlessa heitorlessa changed the title fix(metrics): Add typing to single_metric context manager fix(metrics): explicit type to single_metric ctx manager Dec 8, 2021
@heitorlessa
heitorlessa merged commit e1927d5 into aws-powertools:develop Dec 8, 2021
heitorlessa added a commit that referenced this pull request Dec 8, 2021
@whardier

whardier commented Dec 8, 2021

Copy link
Copy Markdown
Contributor Author

Interesting. I poured over a ton of python code and standard libs and Iterator seemed like the best fit. I will read up on this.

@whardier
whardier deleted the fix/metrics-add-typing-to-single-metric branch December 8, 2021 15:17
@heitorlessa

heitorlessa commented Dec 8, 2021 via email

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants