Skip to content

Deprecate imports when installation has started#13829

Merged
notatallshaw merged 1 commit into
pypa:mainfrom
notatallshaw:disable-imports
Apr 15, 2026
Merged

Deprecate imports when installation has started#13829
notatallshaw merged 1 commit into
pypa:mainfrom
notatallshaw:disable-imports

Conversation

@notatallshaw

@notatallshaw notatallshaw commented Feb 28, 2026

Copy link
Copy Markdown
Member

Towards #13828

Uses the addaudithook approach to what was suggested in the DPO thread on the problems with globally disabling PEP 810 style lazy imports, but had to be expanded a little as various nuances where found while testing.

@notatallshaw

notatallshaw commented Feb 28, 2026

Copy link
Copy Markdown
Member Author

This approach has a reasonable chance of breaking tools which manipulate pip such as pip-tools, and possibly redistributions of pip. If we agree this is the correct approach we should contact Linux distributions and known tools that are coupled to the internals of pip and see what could be done to make it less likely to break or give configuration options.

@notatallshaw notatallshaw changed the title Prevent imports when installation has started Deprecate imports when installation has started Mar 6, 2026
@notatallshaw notatallshaw modified the milestone: 26.1 Mar 6, 2026
@notatallshaw

Copy link
Copy Markdown
Member Author

This approach has a reasonable chance of breaking tools which manipulate pip

I've taken the approach I discuss in #13828 (comment) and turned this into a depreciation which makes it significantly safer to roll out.

@ichard26

ichard26 commented Mar 7, 2026

Copy link
Copy Markdown
Member

This is 100% a drive-by review since I have zero free time, but FWIW, if we're going with a warning initially, I'd want the call stack to be printed (or a truncated one, at least) so we can easily identify where these imports are happening.

@notatallshaw

Copy link
Copy Markdown
Member Author

I'd want the call stack to be printed (or a truncated one, at least) so we can easily identify where these imports are happening.

The file and line number that caused the warning is now included.

@notatallshaw
notatallshaw merged commit 44ef9bc into pypa:main Apr 15, 2026
30 of 34 checks passed
@notatallshaw notatallshaw mentioned this pull request Apr 15, 2026
@notatallshaw

Copy link
Copy Markdown
Member Author

I have no idea how/why this PR got merged, I am reverting and then creating a new clean PR.

@notatallshaw

Copy link
Copy Markdown
Member Author

#13912

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants