Skip to content

✨ feat(py_info): add system_exe, a narrowed system executable - #127

Merged
gaborbernat merged 1 commit into
mainfrom
feat/system-exe
Aug 28, 2026
Merged

✨ feat(py_info): add system_exe, a narrowed system executable#127
gaborbernat merged 1 commit into
mainfrom
feat/system-exe

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Aug 28, 2026

Copy link
Copy Markdown
Member

PythonInfo.system_executable has type str | None, because _fast_get_system_executable() gives up on a virtual environment whose base it cannot determine by inspection. resolve_to_system() then walks the prefix chain and fills the field in, and every discovery entry point runs it before handing a PythonInfo out. 🔍 The annotation cannot express that ordering, so a consumer reading the field past discovery has to narrow a value resolution has settled. virtualenv carries eleven ty: ignore suppressions doing just that, spread across its CPython, PyPy, GraalPy and RustPython creators, and pypa/virtualenv#3223 adds a twelfth.

system_exe gives those callers a reader typed str. It falls back to executable, which carries type str, so the property needs no suppression of its own rather than relocating one out of virtualenv. ✨ This repository follows that same fallback in two other spots. resolve_to_system() writes it when a prefix links back to its own interpreter, and _discovery.py anchors deduplication on it, which docs/explanation.rst records as how iteration skips candidates it has seen. The property sits beside system_prefix and system_exec_prefix, which cover real_prefix or base_prefix or prefix the same way.

Nothing existing changes, since this only adds a reader. _discovery.py could use it too, but the is None guard there cannot fire given executable: str, and untangling that dead branch belongs in its own change.

`system_executable` holds `None` between construction and
`resolve_to_system`, so a consumer reading it after discovery must
narrow a value that resolution has settled. virtualenv carries ten
identical ty suppressions for this one gap.

`system_exe` falls back to `executable`, the value resolution writes
when a prefix links back to its own interpreter, and the anchor
`iter_interpreters` uses for deduplication. It joins `system_prefix` and
`system_exec_prefix` as a narrowed reader of the system interpreter.
@gaborbernat gaborbernat added the enhancement New feature or request label Aug 28, 2026
@gaborbernat
gaborbernat merged commit c9f4e85 into main Aug 28, 2026
19 checks passed
@gaborbernat
gaborbernat deleted the feat/system-exe branch August 28, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant