From d47dfaf844cb9ee021a759ae238d3f2845692ee4 2014-08-11 16:54:39 From: Paul Ivanov Date: 2014-08-11 16:54:39 Subject: [PATCH] Merge pull request #6286 from takluyver/i6282 Fix issue 6282 --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 7d7d0fe..b78654e 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -911,7 +911,8 @@ class InteractiveShell(SingletonConfigurable): try: main_mod = self._main_mod_cache[filename] except KeyError: - main_mod = self._main_mod_cache[filename] = types.ModuleType(modname, + main_mod = self._main_mod_cache[filename] = types.ModuleType( + py3compat.cast_bytes_py2(modname), doc="Module created for script run in IPython") else: main_mod.__dict__.clear() diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index 56211a8..de8d8d7 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -472,6 +472,12 @@ class InteractiveShellTestCase(unittest.TestCase): with open(filename, 'r') as f: self.assertEqual(f.read(), 'blah') + def test_new_main_mod(self): + # Smoketest to check that this accepts a unicode module name + name = u'jiefmw' + mod = ip.new_main_mod(u'%s.py' % name, name) + self.assertEqual(mod.__name__, name) + class TestSafeExecfileNonAsciiPath(unittest.TestCase): @onlyif_unicode_paths