[Python-checkins] r69402 - in python/branches/py3k/Lib/importlib: NOTES _bootstrap.py

brett.cannon python-checkins at python.org
Sat Feb 7 03:13:29 CET 2009


Author: brett.cannon
Date: Sat Feb 7 03:13:28 2009
New Revision: 69402
Log:
Create a simple substitute for functools.wraps to use in importlib._bootstrap.
Modified:
 python/branches/py3k/Lib/importlib/NOTES
 python/branches/py3k/Lib/importlib/_bootstrap.py
Modified: python/branches/py3k/Lib/importlib/NOTES
==============================================================================
--- python/branches/py3k/Lib/importlib/NOTES	(original)
+++ python/branches/py3k/Lib/importlib/NOTES	Sat Feb 7 03:13:28 2009
@@ -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.
Modified: python/branches/py3k/Lib/importlib/_bootstrap.py
==============================================================================
--- python/branches/py3k/Lib/importlib/_bootstrap.py	(original)
+++ python/branches/py3k/Lib/importlib/_bootstrap.py	Sat Feb 7 03:13:28 2009
@@ -90,6 +90,13 @@
 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 @@
 if not hasattr(module, '__path__'):
 module.__package__ = module.__package__.rpartition('.')[0]
 return module
+ wrap(wrapper, fxn)
 return wrapper
 
 
@@ -213,9 +221,7 @@
 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 @@
 elif hasattr(module, attr):
 delattr(module, attr)
 raise
+ wrap(decorated, fxn)
 return decorated
 
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /