From 4b373c421b6795e249bd5e6375d9d079b6b6eaa8 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 26 Feb 2018 23:38:05 +0000 Subject: [PATCH] core: Standardise type of Importer.whitelist This seemed a reasonable streamlining, but I'm happy to be overruled. --- mitogen/core.py | 2 +- tests/importer_test.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mitogen/core.py b/mitogen/core.py index 1634b031..d2d20723 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -420,7 +420,7 @@ class Importer(object): 'utils', ]} self._lock = threading.Lock() - self.whitelist = whitelist or [''] + self.whitelist = list(whitelist) or [''] self.blacklist = list(blacklist) + [ # 2.x generates needless imports for 'builtins', while 3.x does the # same for '__builtin__'. The correct one is built-in, the other diff --git a/tests/importer_test.py b/tests/importer_test.py index 9d533752..55cad182 100644 --- a/tests/importer_test.py +++ b/tests/importer_test.py @@ -32,6 +32,8 @@ class ImporterBlacklist(testlib.TestCase): importer = mitogen.core.Importer( router=mock.Mock(), context=None, core_src='', ) + self.assertIsInstance(importer.whitelist, list) + self.assertIsInstance(importer.blacklist, list) self.assertFalse(mitogen.core.is_blacklisted_import(importer, 'mypkg')) self.assertFalse(mitogen.core.is_blacklisted_import(importer, 'mypkg.mod')) self.assertFalse(mitogen.core.is_blacklisted_import(importer, 'otherpkg')) @@ -44,6 +46,8 @@ class ImporterBlacklist(testlib.TestCase): router=mock.Mock(), context=None, core_src='', whitelist=('mypkg',), ) + self.assertIsInstance(importer.whitelist, list) + self.assertIsInstance(importer.blacklist, list) self.assertFalse(mitogen.core.is_blacklisted_import(importer, 'mypkg')) self.assertFalse(mitogen.core.is_blacklisted_import(importer, 'mypkg.mod')) self.assertTrue(mitogen.core.is_blacklisted_import(importer, 'otherpkg')) @@ -56,6 +60,8 @@ class ImporterBlacklist(testlib.TestCase): router=mock.Mock(), context=None, core_src='', blacklist=('mypkg',), ) + self.assertIsInstance(importer.whitelist, list) + self.assertIsInstance(importer.blacklist, list) self.assertTrue(mitogen.core.is_blacklisted_import(importer, 'mypkg')) self.assertTrue(mitogen.core.is_blacklisted_import(importer, 'mypkg.mod')) self.assertFalse(mitogen.core.is_blacklisted_import(importer, 'otherpkg')) @@ -68,6 +74,8 @@ class ImporterBlacklist(testlib.TestCase): router=mock.Mock(), context=None, core_src='', whitelist=('mypkg',), blacklist=('mypkg',), ) + self.assertIsInstance(importer.whitelist, list) + self.assertIsInstance(importer.blacklist, list) self.assertTrue(mitogen.core.is_blacklisted_import(importer, 'mypkg')) self.assertTrue(mitogen.core.is_blacklisted_import(importer, 'mypkg.mod')) self.assertTrue(mitogen.core.is_blacklisted_import(importer, 'otherpkg'))