Deprecation wrapper

Discussion in 'Python' started by David Hirschfield, Jun 21, 2006.

  1. 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

    --
    Presenting:
    mediocre nebula.
     
    David Hirschfield, Jun 21, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Mitchell
    Replies:
    1
    Views:
    360
  2. Silas Snider

    StringBufferInputStream deprecation

    Silas Snider, Aug 25, 2004, in forum: Java
    Replies:
    2
    Views:
    4,673
    Simon Fairfax
    Aug 25, 2004
  3. e n | c k m a

    <img> deprecation

    e n | c k m a, Aug 19, 2003, in forum: HTML
    Replies:
    4
    Views:
    439
    Headless
    Aug 19, 2003
  4. fuzzylollipop
    Replies:
    3
    Views:
    1,109
    John Carson
    Jan 5, 2005
  5. Meyer, Tony

    FCNTL module deprecation warning

    Meyer, Tony, Jul 15, 2003, in forum: Python
    Replies:
    2
    Views:
    347
    Peter Hansen
    Jul 15, 2003
Loading...

Share This Page