Commit c04d1bdc authored by Brett Cannon's avatar Brett Cannon

Improper type for __package__ should raise TypeError, not ValueError.

parent f9ed1679
...@@ -926,7 +926,7 @@ def _sanity_check(name, package, level): ...@@ -926,7 +926,7 @@ def _sanity_check(name, package, level):
raise ValueError('level must be >= 0') raise ValueError('level must be >= 0')
if package: if package:
if not isinstance(package, str): 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: elif package not in sys.modules:
msg = ("Parent module {0!r} not loaded, cannot perform relative " msg = ("Parent module {0!r} not loaded, cannot perform relative "
"import") "import")
......
...@@ -67,7 +67,7 @@ class Using__package__(unittest.TestCase): ...@@ -67,7 +67,7 @@ class Using__package__(unittest.TestCase):
def test_bunk__package__(self): def test_bunk__package__(self):
globals = {'__package__': 42} globals = {'__package__': 42}
with self.assertRaises(ValueError): with self.assertRaises(TypeError):
import_util.import_('', globals, {}, ['relimport'], 1) import_util.import_('', globals, {}, ['relimport'], 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment