[Python-Dev] @deprecated (was: Useful thread project for 2.5?)

Brett C. bac at OCF.Berkeley.EDU
Wed Mar 9 22:15:06 CET 2005


Stephan Richter wrote:
[SNIP - Michael's deprecated decorator]
> 
> This is a recipe for disaster. Creating a new function from the old can have 
> unwanted side effects, since you effectively change the object. For example, 
> if someone is monkey patching this function, then the deprecation warning 
> gets lost. 
> 

That's the idiom for decorators.  They will almost always be wrappers for other 
functions by returning a new function that uses closures to access the 
original.  Besides, you no longer have the original function directly available 
in the global namespace of the module since the name of the decorated function 
gets rebound before you have a chance to see the original function.  So there 
really is no issue with the function not being the exact same since you can't 
really see it undecorated without a lot of effort; no real change of the object 
that the user can ever tell.

And as for monkey-patching breaking something, that's there fault for 
monkey-patching.  Python doesn't prevent you from doing something stupid which 
why it is the language four out of five adults choose to code in (the fifth 
one, the hold-out, just can't let go of Java because he/she is a recent college 
grad and it is all they have ever known; they also think that EAFP is "evil"  =).

-Brett


More information about the Python-Dev mailing list