Skip to content

BaseSegment defines put_annotation as having return type NoReturn #2002

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

Closed
tibbe opened this issue Mar 13, 2023 · 2 comments · Fixed by #2004
Closed

BaseSegment defines put_annotation as having return type NoReturn #2002

tibbe opened this issue Mar 13, 2023 · 2 comments · Fixed by #2004
Assignees
Labels
bug Something isn't working

Comments

@tibbe
Copy link
Contributor

tibbe commented Mar 13, 2023

Expected Behaviour

The return type should be None. NoReturn means that the function never returns (e.g. it always throws an exception) and makes type checkers (e.g. mypy) mark all code following put_annotation as unreachable.

Also applies to put_metadata, patch, and patch_all.

Current Behaviour

These methods breaks type checking in any modules they're used because all code following a call to e.g. put_annotation is marked as unreachable.

Code snippet

with Tracer().provider.in_subsegment('test') as subsegment:
    subsegment.put_metadata('x', 1)
    print("hi")  # marked as unreachable

Possible Solution

Change the return type to None.

Steps to Reproduce

Use the code snippet above and run mypy on the file.

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

No response

@tibbe tibbe added bug Something isn't working triage Pending triage from maintainers labels Mar 13, 2023
@heitorlessa
Copy link
Contributor

heitorlessa commented Mar 13, 2023 via email

tibbe added a commit to tibbe/aws-lambda-powertools-python that referenced this issue Mar 13, 2023
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 aws-powertools#2002.
@rubenfonseca rubenfonseca self-assigned this Mar 13, 2023
@heitorlessa heitorlessa added pending-release Fix or implementation already in dev waiting to be released and removed triage Pending triage from maintainers labels Mar 16, 2023
@github-actions
Copy link
Contributor

This is now released under 2.10.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants