Skip to content

gh-150167: Force eager import of _bz2 in bz2.py to fix supported format detection - #154771

Open
DavidCEllis wants to merge 7 commits into
python:mainfrom
DavidCEllis:fix-lazy-archive-detection-minimal
Open

gh-150167: Force eager import of _bz2 in bz2.py to fix supported format detection#154771
DavidCEllis wants to merge 7 commits into
python:mainfrom
DavidCEllis:fix-lazy-archive-detection-minimal

Conversation

@DavidCEllis

@DavidCEllis DavidCEllis commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

This adds import _bz2; _bz2 to bz2.py which has the effect of making the import eager even under the 'all' lazy imports mode.

Fixes the issue where bz2 would always be reported as supported by shutil under lazy_imports=all even if it was unavailable. This should also fix this same logic where it's reused in other places (such as test_support).

I think it may make sense to add a SUPPORTED_MODULES attribute to compression that lists which modules are available by checking the internal modules directly, but that can be done on top of this.


The 'import' change that added all of the import codeowners as reviewers:

In order to test that a fresh shutil would correctly identify 'bz2' as unavailable if _bz2 is blocked I needed to add an argument to test.support.import_helpers.import_fresh_module to allow bz2 to be cleared without requiring it successfully re-import. This is the new optional cleared argument.

This new argument is documented, along with the previously undocumented 'usefrozen' argument and the signature in the documentation now correctly identifies the 'deprecated' argument as keyword-only.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33777578 | 📁 Comparing 26e9b64 against main (58d9c78)

  🔍 Preview build  

1 file changed
± library/test.html

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant