From f500778f652f6beb368f10c0fd312c3034dfce5e Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Thu, 23 Feb 2012 18:29:12 -0500 Subject: [PATCH] Improper type for __package__ should raise TypeError, not ValueError. --- Lib/importlib/_bootstrap.py | 2 +- Lib/importlib/test/import_/test___package__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 6382079c19..ccdea85df6 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -926,7 +926,7 @@ def _sanity_check(name, package, level): raise ValueError('level must be >= 0') if package: if not isinstance(package, str): - raise ValueError("__package__ not set to a string") + raise TypeError("__package__ not set to a string") elif package not in sys.modules: msg = ("Parent module {0!r} not loaded, cannot perform relative " "import") diff --git a/Lib/importlib/test/import_/test___package__.py b/Lib/importlib/test/import_/test___package__.py index 5056ae59cc..783cde1729 100644 --- a/Lib/importlib/test/import_/test___package__.py +++ b/Lib/importlib/test/import_/test___package__.py @@ -67,7 +67,7 @@ class Using__package__(unittest.TestCase): def test_bunk__package__(self): globals = {'__package__': 42} - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): import_util.import_('', globals, {}, ['relimport'], 1) -- 2.40.0