[Python-checkins] cpython: Improper type for __package__ should raise TypeError, not ValueError.

brett.cannon python-checkins at python.org
Fri Feb 24 00:30:17 CET 2012


http://hg.python.org/cpython/rev/8d1040fdac60
changeset:   75229:8d1040fdac60
user:        Brett Cannon <brett at python.org>
date:        Thu Feb 23 18:29:12 2012 -0500
summary:
  Improper type for __package__ should raise TypeError, not ValueError.

files:
  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
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -926,7 +926,7 @@
         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
--- a/Lib/importlib/test/import_/test___package__.py
+++ b/Lib/importlib/test/import_/test___package__.py
@@ -67,7 +67,7 @@
 
     def test_bunk__package__(self):
         globals = {'__package__': 42}
-        with self.assertRaises(ValueError):
+        with self.assertRaises(TypeError):
             import_util.import_('', globals, {}, ['relimport'], 1)
 
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list