From eabe8c7c91962a4616bba04c39ea82f110bbc22c Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" Date: Sat, 27 Dec 2025 00:43:07 +0900 Subject: [PATCH 1/2] fix warnings --- crates/vm/src/warn.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/vm/src/warn.rs b/crates/vm/src/warn.rs index b632495eb4..3dbd43ab53 100644 --- a/crates/vm/src/warn.rs +++ b/crates/vm/src/warn.rs @@ -67,8 +67,15 @@ fn get_warnings_attr( Err(_) => return Ok(None), } } else { - // TODO: finalizing support - return Ok(None); + // Check sys.modules for already-imported warnings module + // This is what CPython does with PyImport_GetModule + match vm.sys_module.get_attr(identifier!(vm, modules), vm) { + Ok(modules) => match modules.get_item(vm.ctx.intern_str("warnings"), vm) { + Ok(module) => module, + Err(_) => return Ok(None), + }, + Err(_) => return Ok(None), + } }; Ok(Some(module.get_attr(attr_name, vm)?)) } @@ -320,9 +327,13 @@ fn call_show_warning( return Err(vm.new_type_error("unable to get warnings.WarningMessage")); }; + // Create a Warning instance by calling category(message) + // This is what warnings module does + let warning_instance = category.as_object().call((message,), vm)?; + let msg = warnmsg_cls.call( vec![ - message.into(), + warning_instance, category.into(), filename.into(), vm.new_pyobj(lineno), From 3ccf37ced03029c0585c14dd8f1db59d74fcc82d Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" Date: Sat, 27 Dec 2025 01:06:33 +0900 Subject: [PATCH 2/2] fix test_import --- Lib/test/test_builtin.py | 2 -- Lib/test/test_import/__init__.py | 2 -- Lib/test/test_importlib/import_/test___package__.py | 4 ---- Lib/test/test_importlib/import_/test_helpers.py | 8 -------- Lib/test/test_importlib/import_/test_meta_path.py | 2 -- Lib/test/test_importlib/import_/test_path.py | 2 -- 6 files changed, 20 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 183caa898e..a5306b71d8 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -153,8 +153,6 @@ def check_iter_pickle(self, it, seq, proto): it = pickle.loads(d) self.assertEqual(list(it), seq[1:]) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_import(self): __import__('sys') __import__('time') diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 85913cd7c5..51fafd89ce 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -1403,8 +1403,6 @@ def test_absolute_circular_submodule(self): str(cm.exception), ) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_unwritable_module(self): self.addCleanup(unload, "test.test_import.data.unwritable") self.addCleanup(unload, "test.test_import.data.unwritable.x") diff --git a/Lib/test/test_importlib/import_/test___package__.py b/Lib/test/test_importlib/import_/test___package__.py index 431faea5b4..7130c99a6f 100644 --- a/Lib/test/test_importlib/import_/test___package__.py +++ b/Lib/test/test_importlib/import_/test___package__.py @@ -56,8 +56,6 @@ def test_using___name__(self): '__path__': []}) self.assertEqual(module.__name__, 'pkg') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_warn_when_using___name__(self): with self.assertWarns(ImportWarning): self.import_module({'__name__': 'pkg.fake', '__path__': []}) @@ -75,8 +73,6 @@ def test_spec_fallback(self): module = self.import_module({'__spec__': FakeSpec('pkg.fake')}) self.assertEqual(module.__name__, 'pkg') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_warn_when_package_and_spec_disagree(self): # Raise a DeprecationWarning if __package__ != __spec__.parent. with self.assertWarns(DeprecationWarning): diff --git a/Lib/test/test_importlib/import_/test_helpers.py b/Lib/test/test_importlib/import_/test_helpers.py index 28cdc0e526..550f88d1d7 100644 --- a/Lib/test/test_importlib/import_/test_helpers.py +++ b/Lib/test/test_importlib/import_/test_helpers.py @@ -126,8 +126,6 @@ def test_gh86298_loader_is_none_and_spec_loader_is_none(self): ValueError, _bootstrap_external._bless_my_loader, bar.__dict__) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_gh86298_no_spec(self): bar = ModuleType('bar') bar.__loader__ = object() @@ -137,8 +135,6 @@ def test_gh86298_no_spec(self): DeprecationWarning, _bootstrap_external._bless_my_loader, bar.__dict__) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_gh86298_spec_is_none(self): bar = ModuleType('bar') bar.__loader__ = object() @@ -148,8 +144,6 @@ def test_gh86298_spec_is_none(self): DeprecationWarning, _bootstrap_external._bless_my_loader, bar.__dict__) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_gh86298_no_spec_loader(self): bar = ModuleType('bar') bar.__loader__ = object() @@ -159,8 +153,6 @@ def test_gh86298_no_spec_loader(self): DeprecationWarning, _bootstrap_external._bless_my_loader, bar.__dict__) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_gh86298_loader_and_spec_loader_disagree(self): bar = ModuleType('bar') bar.__loader__ = object() diff --git a/Lib/test/test_importlib/import_/test_meta_path.py b/Lib/test/test_importlib/import_/test_meta_path.py index 26e7b070b9..8689017ba4 100644 --- a/Lib/test/test_importlib/import_/test_meta_path.py +++ b/Lib/test/test_importlib/import_/test_meta_path.py @@ -30,8 +30,6 @@ def test_continuing(self): with util.import_state(meta_path=[first, second]): self.assertIs(self.__import__(mod_name), second.modules[mod_name]) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_empty(self): # Raise an ImportWarning if sys.meta_path is empty. module_name = 'nothing' diff --git a/Lib/test/test_importlib/import_/test_path.py b/Lib/test/test_importlib/import_/test_path.py index 9cf3a77cb8..89b52fbd1e 100644 --- a/Lib/test/test_importlib/import_/test_path.py +++ b/Lib/test/test_importlib/import_/test_path.py @@ -68,8 +68,6 @@ def test_path_hooks(self): self.assertIn(path, sys.path_importer_cache) self.assertIs(sys.path_importer_cache[path], importer) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_empty_path_hooks(self): # Test that if sys.path_hooks is empty a warning is raised, # sys.path_importer_cache gets None set, and PathFinder returns None.