[Python-checkins] r52764 - in python/trunk: Doc/lib/libatexit.tex Lib/atexit.py Misc/NEWS

georg.brandl python-checkins at python.org
Thu Nov 16 17:51:00 CET 2006


Author: georg.brandl
Date: Thu Nov 16 17:50:59 2006
New Revision: 52764
Modified:
 python/trunk/Doc/lib/libatexit.tex
 python/trunk/Lib/atexit.py
 python/trunk/Misc/NEWS
Log:
Bug #1597824: return the registered function from atexit.register()
to facilitate usage as a decorator.
Modified: python/trunk/Doc/lib/libatexit.tex
==============================================================================
--- python/trunk/Doc/lib/libatexit.tex	(original)
+++ python/trunk/Doc/lib/libatexit.tex	Thu Nov 16 17:50:59 2006
@@ -44,6 +44,10 @@
 traceback is printed (unless \exception{SystemExit} is raised) and the
 exception information is saved. After all exit handlers have had a
 chance to run the last exception to be raised is re-raised.
+
+\versionchanged[This function now returns \var{func} which makes it
+ possible to use it as a decorator without binding the
+		original name to \code{None}]{2.6}
 \end{funcdesc}
 
 
@@ -92,3 +96,15 @@
 # or:
 atexit.register(goodbye, adjective='nice', name='Donny')
 \end{verbatim}
+
+Usage as a decorator:
+
+\begin{verbatim}
+import atexit
+
+ at atexit.register
+def goodbye():
+ print "You are now leaving the Python sector."
+\end{verbatim}
+
+This obviously only works with functions that don't take arguments.
Modified: python/trunk/Lib/atexit.py
==============================================================================
--- python/trunk/Lib/atexit.py	(original)
+++ python/trunk/Lib/atexit.py	Thu Nov 16 17:50:59 2006
@@ -40,8 +40,11 @@
 func - function to be called at exit
 targs - optional arguments to pass to func
 kargs - optional keyword arguments to pass to func
+
+ func is returned to facilitate usage as a decorator.
 """
 _exithandlers.append((func, targs, kargs))
+ return func
 
 if hasattr(sys, "exitfunc"):
 # Assume it's another registered exit function - append it to our list
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Thu Nov 16 17:50:59 2006
@@ -98,6 +98,9 @@
 Library
 -------
 
+- Bug #1597824: return the registered function from atexit.register()
+ to facilitate usage as a decorator.
+
 - Patch #1360200: Use unmangled_version RPM spec field to deal with
 file name mangling.
 


More information about the Python-checkins mailing list

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