From 50cccc727a182aa1eeda55a5c075c9452062d3a6 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Mon, 6 Jan 2014 09:54:13 -0600 Subject: make six.moves modules appear not to have __name__ unless they are loaded (fixes #53) --- CHANGES | 6 ++++++ six.py | 11 ++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index d8e3a17..dfd2d7a 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,12 @@ Changelog for Six This file lists the changes in each six version. +1.5.2 +----- + +- Issue #53: Make the fake modules six.moves puts into sys.modules appear not to + have a __name__ unless they are loaded. + 1.5.1 ----- diff --git a/six.py b/six.py index 5dfa78d..fee090d 100644 --- a/six.py +++ b/six.py @@ -106,11 +106,12 @@ class MovedModule(_LazyDescr): def __getattr__(self, attr): # Hack around the Django autoreloader. The reloader tries to get - # __file__ of every module in sys.modules. This doesn't work well if - # this MovedModule is for an module that is unavailable on this machine - # (like winreg on Unix systems). Thus, we pretend __file__ doesn't exist - # if the module hasn't been loaded yet. See issue #51. - if attr == "__file__" and self.mod not in sys.modules: + # __file__ or __name__ of every module in sys.modules. This doesn't work + # well if this MovedModule is for an module that is unavailable on this + # machine (like winreg on Unix systems). Thus, we pretend __file__ and + # __name__ don't exist if the module hasn't been loaded yet. See issues + # #51 and #53. + if attr in ("__file__", "__name__") and self.mod not in sys.modules: raise AttributeError _module = self._resolve() value = getattr(_module, attr) -- cgit v1.2.1