summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-03-13 22:37:55 -0500
committerBenjamin Peterson <benjamin@python.org>2014-03-13 22:37:55 -0500
commit324b371317f66a91094f58046f1a804701c50652 (patch)
treef91e33507ef96e7bbe50c9bd644f5b598deef665
parent543f9487b9ce2db3ea4cd10cb5894e7e14fc137a (diff)
downloadsix-324b371317f66a91094f58046f1a804701c50652.tar.gz
raise an AttributeError for six.moves.X when X is a module not available in the current interpreter
As discussed in https://github.com/pypa/pip/issues/1643.
-rw-r--r--CHANGES6
-rw-r--r--six.py6
-rw-r--r--test_six.py3
3 files changed, 13 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index 01c1e4a..140cae5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,12 @@ Changelog for six
This file lists the changes in each six version.
+1.6.1
+-----
+
+- Raise an AttributeError for six.moves.X when X is a module not available in
+ the current interpreter.
+
1.6.0
-----
diff --git a/six.py b/six.py
index ad34014..6b6ad9f 100644
--- a/six.py
+++ b/six.py
@@ -83,7 +83,11 @@ class _LazyDescr(object):
self.name = name
def __get__(self, obj, tp):
- result = self._resolve()
+ try:
+ result = self._resolve()
+ except ImportError:
+ # See the nice big comment in MovedModule.__getattr__.
+ raise AttributeError("%s could not be imported " % self.name)
setattr(obj, self.name, result) # Invokes __set__.
# This is a bit ugly, but it avoids running this again.
delattr(obj.__class__, self.name)
diff --git a/test_six.py b/test_six.py
index 45649b2..47ad1ce 100644
--- a/test_six.py
+++ b/test_six.py
@@ -113,7 +113,8 @@ def test_move_items(item_name):
if item_name.startswith("dbm_gnu") and not have_gdbm:
py.test.skip("requires gdbm")
raise
- assert item_name in dir(six.moves)
+ if sys.version_info[:2] >= (2, 6):
+ assert item_name in dir(six.moves)
@py.test.mark.parametrize("item_name",