Skip to content

Fall back when Python environments API is incomplete - #81

Merged
Eduardo Villalpando Mello (edvilme) merged 2 commits into
microsoft:mainfrom
Pybsama:codex/fallback-incomplete-python-environments-api
Nov 20, 2026
Merged

Eduardo Villalpando Mello (edvilme) merged 2 commits into
microsoft:mainfrom
Pybsama:codex/fallback-incomplete-python-environments-api

Conversation

@Pybsama

@Pybsama sama Pyb (Pybsama) commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • validate the preferred Python Environments API's required runtime capabilities before wrapping or caching it
  • fall back to the legacy Python Extension API for undefined, null, or incomplete preferred exports
  • keep project and package capabilities optional, including harmless missing or throwing package-event subscriptions
  • preserve current interpreter selection, arguments, version handling, caching, and environment/project event behavior

Context

When the Python Environments integration is disabled, the installed extension can return undefined exports without throwing. The shared provider previously cached that result and later failed while subscribing to environment/package events instead of trying its existing legacy fallback.

This change belongs in the source-pinned shared runtime consumed by Pylint and the other VS Code Python tool extensions. This repository does not independently release npm/PyPI packages; there is no version bump or release-workflow version synchronization. Dependencies, lockfiles, serialized settings defaults, Python runtime source, and consumer pins are unchanged. Consumer updates remain separate work.

Addresses microsoft/vscode-pylint#856.

Current main (0425ee5673d3f8f8abb055a424bcb9aa52132eb9) was merged into the original PR history without rebasing or force-pushing. The signed update is e46a48f887bccc67b9322242c5f8ad84cc4e0176.

The delta remains focused on typescript/src/python.ts and typescript/tests/python.test.ts, plus a necessary two-line update to the existing typescript/tests/toolExtension.test.ts mock: a healthy preferred API fixture must now include resolveEnvironment.

Validation — 2026-11-18

Using Node 24.17.0, pinned by .nvmrc, from typescript:

  • Removing only the production capability guard makes all 8/8 targeted incomplete-export regressions fail; restoring it passes them.
  • npm test -- --grep PythonEnvironmentsProvider --reporter dot: 32 passing.
  • npm test -- --grep 'PythonEnvironmentsProvider|activateToolExtension' --reporter dot: 45 passing.
  • npm test -- --reporter dot: 199 passing (includes the test compilation step).
  • npm run build: passed.
  • npm run lint: passed, with two pre-existing unused eslint-disable warnings in untouched src/vscodeapi.ts.
  • npx --no-install prettier --check --single-quote --tab-width 4 --print-width 120 src/python.ts tests/python.test.ts: passed, preserving the existing source style.
  • git diff --check: passed.

The default npm run format-check reports the same 15 source-file warnings as untouched current main; unrelated files were not mass-formatted. The activation test file also has pre-existing formatting differences under the explicit style options, verified against untouched main; its only changes are the two fixture lines.

Python source is unchanged, so no fresh Python environment was created and Python tests were not rerun for this TypeScript-only fix. A real VS Code/Pylint manual smoke test has not been run.

@Pybsama

Copy link
Copy Markdown
Contributor Author

Revalidated this change against current main at f839a70789f28ccd96f428d51685d60f07b5189c. The six commits since the PR base do not touch either PR file; the PR applies without conflicts, and the exact current-main merge tree is 6298a54342c9d9389d1fed8929d3dd54cfa1bb6f.

The runtime case remains relevant: current main still pins @vscode/python-environments 1.0.0, whose helper returns extension.exports without validating it.

Current-main validation:

  • removing only the capability guard/no-op fallback makes all 3 focused regressions fail; restoring the patch gives 3/3, plus 100/100 consecutive focused repetitions
  • Node 24.17.0: 134/134 TypeScript tests, test build, package build, and ESLint passed
  • CPython 3.10.20: 334/334 tests; Flake8, Black, isort, version consistency, and dependency checks passed
  • package dry run: 58 entries; compiled dist/python.js contains the capability guard and optional-event fallback
  • git diff --check: passed; the patch remains 2 files with no dependency or version changes
  • npm run format-check reports the same 14 pre-existing source warnings on untouched current main and the merge tree; that script is not part of the PR workflow

The upstream run now has 19 successful checks, including Linux/Windows Python 3.10–3.14, TypeScript, both CodeQL analyses, version checks, and CLA. The only failure is Ensure Required Labels, whose annotation requires one of bug, debt, dependencies, feature-request, or no-changelog; the repository reports my permission as READ, so a maintainer needs to apply the appropriate label.

The public head remains the original GitHub-verified commit because GitHub reports the PR as mergeable and the current-main changes do not overlap the patch. Marking this ready for maintainer review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation addresses the reported failure with focused, comprehensive tests and no unresolved issues.

Pull request overview

Adds robust fallback behavior when the preferred Python Environments API is unavailable or incomplete.

Changes:

  • Validates required API capabilities before caching.
  • Falls back to the legacy Python API.
  • Treats package-change events as optional with a no-op disposable.
File summaries
File Description
typescript/src/python.ts Implements API validation, fallback, and optional package events.
typescript/tests/python.test.ts Tests fallback, caching, and missing optional events.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@edvilme

Copy link
Copy Markdown
Contributor

sama Pyb (@Pybsama)
Hello! Thank you for your fix! We have made some changes since your last commit on both the environments extension and this repo. If you have the time to solve the merge conflicts so we can review, we would appreciate that greatly! If not, no worries, we will take care of that. Thanks for your contribution!

Preserve PR81 history while validating required preferred API capabilities, retaining optional events and extending focused regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 85ef72cc-9e26-4bc4-b1c3-55256d9bef91

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the Python API fallback changes.

No open issues 🎉

Review effort: Balanced

@edvilme

Copy link
Copy Markdown
Contributor

Tested locally with extensions and everything looks great! Thank you very much for picking this up :)

@edvilme
Eduardo Villalpando Mello (edvilme) merged commit ef8e0bf into microsoft:main Nov 20, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants