Skip to content

Return type hint for SubsegmentContextManager.__enter__ in aws-xray-sdk should include None #13883

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
allanlewis opened this issue Apr 25, 2025 · 3 comments · Fixed by #13892
Closed
Labels
stubs: false negative Type checkers do not report an error, but should

Comments

@allanlewis
Copy link
Contributor

The return type hint for SubsegmentContextManager.__enter__ is Subsegment, but the implementation can clearly return None. The type hint should therefore be Optional[Subsegment] or equivalent.

This has hit me when running tests on X-Ray-instrumented code, when there isn't a segment to derive from. I then end up with NREs as Mypy thinks that in_subsegment should have yielded a Subsegment.

@srittau srittau added the stubs: false negative Type checkers do not report an error, but should label Apr 25, 2025
@srittau
Copy link
Collaborator

srittau commented Apr 25, 2025

PR welcome!

@tmlnv
Copy link
Contributor

tmlnv commented Apr 27, 2025

Hi, @srittau , here is the PR.

@allanlewis
Copy link
Contributor Author

Thanks, @tmlnv!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false negative Type checkers do not report an error, but should
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants