FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-150167: Prevent successful import of `bz2` under lazy_imports=all if `_bz2` is unavailable by DavidCEllis · Pull Request #157321 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions Lib/bz2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io
import os

import _bz2; _bz2 # Force the eager import of _bz2
from _bz2 import BZ2Compressor, BZ2Decompressor


Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_bz2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,20 @@ def test_newline(self):
self.assertEqual(f.readlines(), [text])


class TestMissingModuleImport(unittest.TestCase):
# Test that module import fails if _bz2 is not available
# See: https://github.com/python/cpython/issues/150167
@support.thread_unsafe("Modifies global import state")
def test_under_lazy_all(self):
import_state = sys.get_lazy_imports()
try:
sys.set_lazy_imports("all")
with self.assertRaises(ImportError):
import_helper.import_fresh_module("bz2", blocked=("_bz2",))
finally:
sys.set_lazy_imports(import_state)


def tearDownModule():
support.reap_children()

Expand Down
Loading

Back | FazBrowse Home | New Git URL