Repository navigation
ci(mypy): Enable possibly-undefined error code - #8290
Draft
sentry-junior[bot] wants to merge 2 commits into
Draft
sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
Turn on mypy's possibly-undefined check and fix the existing errors it reports, mostly by initializing variables or restructuring branches so mypy can see they are always bound. Co-Authored-By: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
…defined # Conflicts: # pyproject.toml
Contributor
Coverage Results 📊✅ 139266 passed | ⏭️ 7853 skipped | Total: 147119 | Pass Rate: 94.66% | Execution Time: 447m 45s 📊 Comparison with Base Branch
✨ Test counts unchanged from base. All tests are passing successfully. ✅ Patch coverage is 88.24% (15 of 17 changed executable lines covered; target 80%). Changed files with executable lines (10)
Coverage diff@@ Coverage Diff @@
## master #8290 +/-##
==========================================
Coverage 90.21% 90.21% —%
==========================================
Files 203 203 —
Tracked lines 27335 27336 +1
Branches 10246 10240 -6
==========================================
+ Hits 24660 24661 +1
Misses 2675 2675 —
+ Partials 1559 1557 -2Generated by Coverage Action |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Turns on mypy's
possibly-undefinederror code. It flags names that are only assigned on some code paths (in oneifbranch, inside atry, in a conditional import) and then used where they might not be bound. At runtime that's anUnboundLocalError, which in the SDK would crash the host app's code path.It reported 15 errors in 11 files. Nearly all were correct code that mypy couldn't prove was safe. They're fixed without changing behavior:
name = Nonein the Litestar/Starlite route handler patch (falls through to the existing_DEFAULT_TRANSACTION_NAMEfallback), and movedagent_name = Noneout of thetryinlangchain._get_request_data.transport.py: returnPoolManagerstraight from the SOCKSexcept ImportErrorinstead of tracking ause_socks_proxyflag.spotlight.py: computespotlight_js_urlbefore thetry.urljoindoesn't raiseURLError, so the exception handling stays the same.chalice.py: pick the patched class once and use it for both reading and patching_get_view_function_response, instead of checking the version twice.grpc/aio/server.py: the last of the four exhaustiverequest_streaming/response_streamingbranches is nowelse.stdlib.py:set_on_spanstarts asNoneand the tunnel block checks it instead ofspan. They're set together, and spans don't define__bool__, so the two checks are equivalent.beam.raise_exceptionalways re-raises, so it now returnsNoReturninstead ofNone.Latent bugs, fixed minimally (I don't know of a real trigger for either):
mcp.py:_tool_handler_wrapperand_prompt_handler_wrapperleavehandler_nameunbound if they get no positional args and no truthynamekwarg. That raisesUnboundLocalErrorbefore the user's handler runs. Both now default to"unknown", the same as_resource_handler_wrapperalready does.quart.py:_request_websocket_startedleavesrequest_websocketunbound if neither a request nor a websocket context is active. That shouldn't happen forrequest_started/websocket_startedsignals. It now returns early in that case. The branches are reordered so the websocket context still wins when both are active, as before.enable_error_codenow lists bothpossibly-undefinedandunused-awaitable(from #8281, merged into this branch). The sibling mypy follow-up PRs will still conflict trivially on that line; merge the lists when rebasing.Follow-up from #8281.
via @sentrivana.
--
View Session [Sentry]