[Zope3-checkins]
SVN: Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/
Fix a bug in zope.deprecation.deprecated that would not allow
it to be called
Philipp von Weitershausen
philikon at philikon.de
Sun Feb 19 08:12:18 EST 2006
Log message for revision 41701:
Fix a bug in zope.deprecation.deprecated that would not allow it to be called
from inside a function.
Changed:
U Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/README.txt
U Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/deprecation.py
U Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/tests.py
-=-
Modified: Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/README.txt
===================================================================
--- Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/README.txt 2006-02-19 12:39:36 UTC (rev 41700)
+++ Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/README.txt 2006-02-19 13:12:18 UTC (rev 41701)
@@ -60,6 +60,20 @@
>>> tests.demo1
1
+Deprecation can also happen inside a function. When we first access
+``demo4``, it can be accessed without problems, then we call a
+function that sets the deprecation message and we get the message upon
+the next access:
+
+ >>> tests.demo4
+ 4
+ >>> tests.deprecatedemo4()
+ >>> tests.demo4
+ From tests.py's showwarning():
+ ...README.txt:1: DeprecationWarning: demo4: demo4 is no more.
+ ...
+ 4
+
New let's see how properties and methods can be deprecated. We are going to
use the same function as before, except that this time, we do not pass in names
as first argument, but the method or attribute itself. The function then
Modified: Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/deprecation.py
===================================================================
--- Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/deprecation.py 2006-02-19 12:39:36 UTC (rev 41700)
+++ Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/deprecation.py 2006-02-19 13:12:18 UTC (rev 41701)
@@ -131,9 +131,8 @@
# We are inside a module
if isinstance(specifier, (str, unicode, list, tuple)):
- locals = sys._getframe(1).f_locals
- if '__name__' in locals:
- modname = locals['__name__']
+ globals = sys._getframe(1).f_globals
+ modname = globals['__name__']
if not isinstance(sys.modules[modname], DeprecationProxy):
sys.modules[modname] = DeprecationProxy(sys.modules[modname])
Modified: Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/tests.py
===================================================================
--- Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/tests.py 2006-02-19 12:39:36 UTC (rev 41700)
+++ Zope3/branches/philikon-simplify-skinning/src/zope/deprecation/tests.py 2006-02-19 13:12:18 UTC (rev 41701)
@@ -13,7 +13,7 @@
##############################################################################
"""Component Architecture Tests
-$Id: test_api.py 28632 2004-12-16 17:42:59Z srichter $
+$Id$
"""
import sys
import unittest
@@ -31,6 +31,10 @@
demo3 = 3
deprecated('demo3', 'demo3 is no more.')
+demo4 = 4
+def deprecatedemo4():
+ """Demonstrate that deprecate() also works in a local scope."""
+ deprecated('demo4', 'demo4 is no more.')
orig_showwarning = warnings.showwarning
More information about the Zope3-Checkins
mailing list