Skip to content

Support PEP 810 lazy imports (Python 3.15) - #2094

Merged
Rich Chiodo (rchiodo) merged 1 commit into
microsoft:mainfrom
aperez:pep810-lazy-imports
Nov 10, 2026
Merged

Rich Chiodo (rchiodo) merged 1 commit into
microsoft:mainfrom
aperez:pep810-lazy-imports

Conversation

@aperez

Copy link
Copy Markdown
Contributor

With lazy imports enabled globally (-X lazy_imports=all or PYTHON_LAZY_IMPORTS=all), module-level imports can be deferred until first use, which breaks the places where debugpy relies on import side effects. force_pydevd never runs, and the vendored pydevd modules and attach_pid_injected are only resolved after their directories have been removed from sys.path, so debugpy fails to start or attach.

vendored() now switches lazy imports to "normal" while the vendored project is on sys.path, and the side-effect imports use __import__(), which is never deferred. tests/debugpy/test_lazy_imports.py runs every runner with PYTHON_LAZY_IMPORTS=all.

With lazy imports enabled globally (`-X lazy_imports=all` or `PYTHON_LAZY_IMPORTS=all`), module-level imports can be deferred until first use, which breaks the places where debugpy relies on import side effects. `force_pydevd` never runs, and the vendored pydevd modules and `attach_pid_injected` are only resolved after their directories have been removed from `sys.path`, so debugpy fails to start or attach.

`vendored()` now switches lazy imports to `"normal"` while the vendored project is on `sys.path`, and the side-effect imports use `__import__()`, which is never deferred. `tests/debugpy/test_lazy_imports.py` runs every runner with `PYTHON_LAZY_IMPORTS=all`.
@aperez
Alexandre Perez (aperez) requested a review from a team as a code owner November 10, 2026 01:36
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@rchiodo

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@rchiodo
Rich Chiodo (rchiodo) merged commit 8294469 into microsoft:main Nov 10, 2026
23 of 26 checks passed
@rchiodo

Copy link
Copy Markdown
Contributor

Finn Womack (@finnagin), we might need this for debugpy v2?

@aperez
Alexandre Perez (aperez) deleted the pep810-lazy-imports branch November 10, 2026 19:27
@aperez

Copy link
Copy Markdown
Contributor Author

Finn Womack (Finn Womack (@finnagin)), we might need this for debugpy v2?

Rich Chiodo (@rchiodo) can you share any information about debugpy v2? Is it related to the v2 branch in this repository?

@rchiodo

Copy link
Copy Markdown
Contributor

Finn Womack (Finn Womack (Finn Womack (@finnagin))), we might need this for debugpy v2?

Rich Chiodo (Rich Chiodo (@rchiodo)) can you share any information about debugpy v2? Is it related to the v2 branch in this repository?

Yes it's related to that branch. I don't know if I can say anything more than that.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants