summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-01-04 17:35:43 -0600
committerBenjamin Peterson <benjamin@python.org>2014-01-04 17:35:43 -0600
commit7650f8beb6cf9d5d8c8f722cf09df888d278af86 (patch)
tree56e0a7f68668cef4f4d606290bf154dae05e21b8
parentf2622c16be1e9362a1b8b5b75b8bd9e4da60a498 (diff)
parentf293ede1501e852dd16922eb33f6ede9d69edcc6 (diff)
downloadsix-7650f8beb6cf9d5d8c8f722cf09df888d278af86.tar.gz
Merged in msabramo/six/issue_19 (pull request #18)
Put six.moves modules in sys.modules so that they're importable (fixes
-rw-r--r--six.py8
-rw-r--r--test_six.py14
2 files changed, 21 insertions, 1 deletions
diff --git a/six.py b/six.py
index 3887a06..4e53304 100644
--- a/six.py
+++ b/six.py
@@ -104,6 +104,12 @@ class MovedModule(_LazyDescr):
def _resolve(self):
return _import_module(self.mod)
+ def __getattr__(self, attr):
+ _module = self._resolve()
+ value = getattr(_module, attr)
+ setattr(self, attr, value)
+ return value
+
class _LazyModule(types.ModuleType):
@@ -212,6 +218,8 @@ _moved_attributes = [
]
for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
+ if isinstance(attr, MovedModule):
+ sys.modules[__name__ + ".moves." + attr.name] = attr
del attr
_MovedItems._moved_attributes = _moved_attributes
diff --git a/test_six.py b/test_six.py
index e6e75dd..14f0e7e 100644
--- a/test_six.py
+++ b/test_six.py
@@ -96,7 +96,9 @@ except ImportError:
def test_move_items(item_name):
"""Ensure that everything loads correctly."""
try:
- getattr(six.moves, item_name)
+ item = getattr(six.moves, item_name)
+ if isinstance(item, types.ModuleType):
+ __import__("six.moves." + item_name)
except AttributeError:
if item_name == "zip_longest" and sys.version_info < (2, 6):
py.test.skip("zip_longest only available on 2.6+")
@@ -183,6 +185,16 @@ def test_import_moves_error_3():
from six.moves.urllib_parse import urljoin
+def test_from_six_moves_queue_import_Queue():
+ from six.moves.queue import Queue
+ assert isinstance(Queue, types.ClassType)
+
+
+def test_from_six_moves_configparser_import_ConfigParser():
+ from six.moves.configparser import ConfigParser
+ assert isinstance(ConfigParser, types.ClassType)
+
+
def test_filter():
from six.moves import filter
f = filter(lambda x: x % 2, range(10))