Deprecation wrapper

D

David Hirschfield

I have a "deprecation" wrapper that allows me to do this:

def oldFunc(x,y):
...

def newFunc(x,y):
...

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:

class OldClass:
...

class NewClass:
...

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,
-David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top