Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Conversation

whardier
Copy link
Contributor

@whardier whardier commented Dec 2, 2021

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
Copy link

codecov-commenter commented Dec 2, 2021

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.

Copy link
Contributor

@heitorlessa heitorlessa left a comment

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.

aws_lambda_powertools/metrics/metric.py Outdated Show resolved Hide resolved
aws_lambda_powertools/metrics/metric.py Outdated Show resolved Hide resolved
@heitorlessa
Copy link
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
Copy link
Contributor Author

whardier commented Dec 8, 2021

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
Copy link
Contributor

heitorlessa commented Dec 8, 2021 via email

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