Skip to content

Conversation

@tannguyencse19
Copy link

Summary

Update to: Only let the finally block override the try path analysis when the finally block itself always terminates, for example it always returns or always raises.

If the finally block can fall through, analyze the try body, else, and handlers as usual.

Fixes #1091

Test Plan

cargo test test_return_try_finally_explicit_return

@yangdanny97
Copy link
Contributor

Hmm, the linked issue was fixed by #1118, but I actually don't think that PR is correct. Let me discuss with the team

@yangdanny97 yangdanny97 self-assigned this Dec 29, 2025
@github-actions
Copy link

Diff from mypy_primer, showing the effect of this PR on open source code:

scipy (https://github.com/scipy/scipy)
- ERROR scipy/optimize/_tstutils.py:135:24-25: Cannot set item in `dict[Unknown, None]` [unsupported-operation]
- ERROR scipy/stats/_axis_nan_policy.py:238:37-56: No matching overload found for function `numpy._typing._ufunc._UFunc_Nin2_Nout1.__call__` called with arguments: (type[float64] | int | Unknown, float) [no-matching-overload]

typeshed-stats (https://github.com/AlexWaygood/typeshed-stats)
- ERROR src/typeshed_stats/gather.py:999:28-1002:10: `Pattern[Unknown] | @6887 | None` is not assignable to upper bound `bytes | str` of type variable `AnyStr` [bad-specialization]
+ ERROR src/typeshed_stats/gather.py:999:28-1002:10: `Pattern[Unknown] | @7027 | None` is not assignable to upper bound `bytes | str` of type variable `AnyStr` [bad-specialization]

@yangdanny97
Copy link
Contributor

After discussions w/ the team, I realize I misunderstood the previous PR. That is an adequate fix for the original issue, so this PR should not be necessary - the added test case passes without it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect return path identification with try/finally

2 participants