davidh at ilm.com
Wed Jun 21 01:48:34 CEST 2006
I have a "deprecation" wrapper that allows me to do this:
oldFunc = deprecated(oldFunc, newFunc)
It basically wraps the definition of "oldFunc" with a DeprecationWarning
and some extra messages for code maintainers, and also prompts them to
look at "newFunc" as the replacement. This way, anyone who calls
oldFunc() will get the warning and messages automatically.
I'd like to expand this concept to classes and values defined in my
modules as well.
So, I'd like a deprecatedClass that would somehow take:
OldClass = deprecatedClass(OldClass, NewClass)
and would similarly give the warning and other messages when someone
tried to instantiate an OldClass object.
And, for general values, I'd like:
OLD_CONSTANT = "old"
NEW_CONSTANT = "new"
OLD_CONSTANT = deprecatedValue(OLD_CONSTANT, NEW_CONSTANT)
so any attempt to use OLD_CONSTANT (or just the first attempt) would
also output the warning and associated messages.
I think that setting it up for classes would just mean making a wrapper
class that generates the warning in its __init__ and then wraps the
instantiation of the old class.
But how can I do something similar for plain values like those constants?
Is there a better way to do this whole thing, in general? Anyone already
have a similar system set up?
Thanks in advance,
More information about the Python-list