summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-02-07 02:13:28 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-02-07 02:13:28 (GMT)
commit51d8bfc8373d4275dfbf7ff24b2d594d753d9e1f (patch)
tree4ec373b4c1cee2417baaeadd6c3d547446ade0fe /Lib
parent534b2cd176a0440b59980d97723e109638216c1c (diff)
downloadcpython-51d8bfc8373d4275dfbf7ff24b2d594d753d9e1f.zip
cpython-51d8bfc8373d4275dfbf7ff24b2d594d753d9e1f.tar.gz
cpython-51d8bfc8373d4275dfbf7ff24b2d594d753d9e1f.tar.bz2
Create a simple substitute for functools.wraps to use in importlib._bootstrap.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/NOTES2
-rw-r--r--Lib/importlib/_bootstrap.py13
2 files changed, 10 insertions, 5 deletions
diff --git a/Lib/importlib/NOTES b/Lib/importlib/NOTES
index e1ec98d..a9f0c17 100644
--- a/Lib/importlib/NOTES
+++ b/Lib/importlib/NOTES
@@ -1,8 +1,6 @@
to do
/////
-* Backport a poor-man's functools.wraps.
-
* Implement PEP 302 protocol for loaders (should just be a matter of testing).
+ Built-in.
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 810f793..54e2f9d 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -90,6 +90,13 @@ class closing:
self.obj.close()
+def wrap(new, old):
+ """Simple substitute for functools.wraps."""
+ for replace in ['__module__', '__name__', '__doc__']:
+ setattr(new, replace, getattr(old, replace))
+ new.__dict__.update(old.__dict__)
+
+
def set___package__(fxn):
"""Set __package__ on the returned module."""
def wrapper(*args, **kwargs):
@@ -99,6 +106,7 @@ def set___package__(fxn):
if not hasattr(module, '__path__'):
module.__package__ = module.__package__.rpartition('.')[0]
return module
+ wrap(wrapper, fxn)
return wrapper
@@ -213,9 +221,7 @@ def check_name(method):
if self._name != name:
raise ImportError("loader cannot handle %s" % name)
return method(self, name, *args, **kwargs)
- inner.__name__ = method.__name__
- inner.__doc__ = method.__doc__
- inner.__dict__.update(method.__dict__)
+ wrap(inner, method)
return inner
@@ -318,6 +324,7 @@ def get_module(fxn):
elif hasattr(module, attr):
delattr(module, attr)
raise
+ wrap(decorated, fxn)
return decorated