[Python-checkins] cpython: Issue #13593: updating the importlib utility decorators for __qualname__.

meador.inge python-checkins at python.org
Thu Dec 15 05:55:07 CET 2011


http://hg.python.org/cpython/rev/54a77c556d9a
changeset:   73977:54a77c556d9a
user:        Meador Inge <meadori at gmail.com>
date:        Wed Dec 14 22:53:13 2011 -0600
summary:
  Issue #13593: updating the importlib utility decorators for __qualname__.

files:
  Lib/importlib/_bootstrap.py     |   2 +-
  Lib/importlib/test/test_util.py |  10 ++++++++++
  2 files changed, 11 insertions(+), 1 deletions(-)


diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -111,7 +111,7 @@
 
 def _wrap(new, old):
     """Simple substitute for functools.wraps."""
-    for replace in ['__module__', '__name__', '__doc__']:
+    for replace in ['__module__', '__name__', '__qualname__', '__doc__']:
         setattr(new, replace, getattr(old, replace))
     new.__dict__.update(old.__dict__)
 
diff --git a/Lib/importlib/test/test_util.py b/Lib/importlib/test/test_util.py
--- a/Lib/importlib/test/test_util.py
+++ b/Lib/importlib/test/test_util.py
@@ -59,6 +59,11 @@
             self.raise_exception(name)
             self.assertIs(module, sys.modules[name])
 
+    def test_decorator_attrs(self):
+        def fxn(self, module): pass
+        wrapped = util.module_for_loader(fxn)
+        self.assertEqual(wrapped.__name__, fxn.__name__)
+        self.assertEqual(wrapped.__qualname__, fxn.__qualname__)
 
 class SetPackageTests(unittest.TestCase):
 
@@ -108,6 +113,11 @@
             module.__package__ = value
             self.verify(module, value)
 
+    def test_decorator_attrs(self):
+        def fxn(module): pass
+        wrapped = util.set_package(fxn)
+        self.assertEqual(wrapped.__name__, fxn.__name__)
+        self.assertEqual(wrapped.__qualname__, fxn.__qualname__)
 
 def test_main():
     from test import support

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list