Skip to content

fix(typing): swap NoReturn with None for methods with no return value#2004

Merged
rubenfonseca merged 1 commit into
aws-powertools:developfrom
tibbe:no-return
Mar 13, 2023
Merged

fix(typing): swap NoReturn with None for methods with no return value#2004
rubenfonseca merged 1 commit into
aws-powertools:developfrom
tibbe:no-return

Conversation

@tibbe

@tibbe tibbe commented Mar 13, 2023

Copy link
Copy Markdown
Contributor

Issue number: #2002

Summary

NoReturn are for methods that never return (e.g. always raise exceptions). Using NoReturn causes e.g. mypy to think all code following the call to the NoReturn method to be unreachable.

Changes

The

  • put_annotation
  • put_metadata
  • patch
  • patch_all

methods of BaseSegment now have the correct return type for methods that return not (but do in fact return).

User experience

Before this change using any of the above methods would lead to type errors/unreachable code errors when used with e.g. mypy.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

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

Acknowledgment

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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

NoReturn are for methods that never return (e.g. always raise
exceptions). Using NoReturn causes e.g. mypy to think all code following
the call to the NoReturn method to be unreachable.

Fixes #2002.
@tibbe tibbe requested a review from a team as a code owner March 13, 2023 13:48
@tibbe tibbe requested review from rubenfonseca and removed request for a team March 13, 2023 13:48
@boring-cyborg boring-cyborg Bot added the tracer Tracer utility label Mar 13, 2023
@pull-request-size pull-request-size Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 13, 2023
@boring-cyborg

boring-cyborg Bot commented Mar 13, 2023

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our AWS Lambda Powertools Discord: Invite link

@github-actions github-actions Bot added the bug Something isn't working label Mar 13, 2023
@rubenfonseca rubenfonseca changed the title fix(typing): Don't use NoReturn for methods that return None fix(typing): swap NoReturn with None for methods with no return value Mar 13, 2023
@rubenfonseca

Copy link
Copy Markdown
Contributor

@tibbe thank you so much for reporting and fixing this so quickly! We really appreciate this, and we will release this to the public later this week

@rubenfonseca rubenfonseca merged commit e9b4f54 into aws-powertools:develop Mar 13, 2023
@boring-cyborg

boring-cyborg Bot commented Mar 13, 2023

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@rubenfonseca rubenfonseca linked an issue Mar 13, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tracer Tracer utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BaseSegment defines put_annotation as having return type NoReturn

2 participants