Deprecation wrapper

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Hirschfield

    #1

    Deprecation wrapper

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

    def oldFunc(x,y):
    ...

    def newFunc(x,y):
    ...

    oldFunc = deprecated(oldF unc, newFunc)

    It basically wraps the definition of "oldFunc" with a DeprecationWarn ing
    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

    --
    Presenting:
    mediocre nebula.

Working...