Repository navigation
Fix the dead guard around base interpreter resolution in interpreter inspect - #3337
Open
qianeric-backup wants to merge 1 commit into
Open
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
… inspect` The base interpreter of a venv is resolved inside a try/except that logs a warning on BaseInterpreterResolutionError (pex-tool#3113), and then resolved again right after the except block without a guard. That second assignment makes the guard dead code: the warning is logged and the command still fails with the error it just caught, and no JSON is produced. On the success path it also resolves the base interpreter twice, spawning a subprocess each time. Drop the duplicated assignment so the guarded one is the only one.
qianeric-backup
marked this pull request as ready for review
November 28, 2026 15:45
Member
|
Thanks for the report and PR @qianeric-backup. Your PR description smacks of AI; so I want to make sure you saw the opening sentences here: https://github.com/pex-tool/pex/blob/main/CONTRIBUTING.md#contributing That aside, there is a real test failure on Mac for you to address that is due to Mac's unique Framework Python builds not meeting your test assumptions. The other failure is being addressed in #3336 (which will likely stomp your version bump / CHANGELOG edit). |
Member
|
@qianeric-backup if the AI contribution criteria takes you out of the running, please let me know and I'll close this (or you can). Otherwise I'll close on Friday, December 11th if I've heard no response. |
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.
Problem
pex3 interpreter inspectresolves the base interpreter of avenvinside atry/exceptwhose whole purpose is to survive a failure (the guard added for #3113), and then immediately does the same resolution again, unguarded:The second assignment makes the guard dead code: the warning is logged and the command then fails anyway with the same error it just caught. On the success path the base interpreter is resolved twice, and each resolution spawns a subprocess.
Reproduced with a virtualenv created from a
--copiesbase interpreter whose binary is then moved away (the venv still runs, but its base interpreter can no longer be found):No JSON is produced at all, so
-von a venv always fails when the base interpreter cannot be resolved, even though the only consumer ofbase_interpreteris treated as optional by the code above it.Fix
Remove the duplicated assignment, leaving the guarded one. The key is simply absent when the base interpreter cannot be resolved, which is what the
exceptbranch already intends, and the success path resolves it once instead of twice.Test
tests/integration/cli/commands/test_interpreter_inspect.pygains a case that builds such a venv and asserts that the inspect still succeeds with JSON output, thatbase_interpreteris simply absent from it, and that the warning is still logged. Without the fix it fails with a non-zero exit and empty stdout. The single resolution on the success path is visible in the call count rather than asserted in the test:resolve_base_interpreter()is called twice before the change and once after it.Notes on the existing suite
The integration suite needs network access (
uv sync --frozen, pip downloads, URL fetches), so the failures around it change from run to run on this machine: the same test can fail and then pass on an unchanged tree. Nothing in the changed code is reachable from those tests; the case above is the only one that covers this branch.Release notes
CHANGES.mdgains a## 2.107.2section andpex/version.pyis bumped, following the convention of the previous release commit (#3329).