Creating a new function with lesser arguments by wrapping the old function on it


Suppose I have an old function, oldFunction(first, second, third). And, all the arguments are mandatory. I want to deprecate the use of 'second' argument, and also not change the code anywhere in my project.

So I want to create a new function which does exactly the same thing, with only the first and the third argument.

So, I was thinking of wrapping the new function with new signature with old function as the wrapper. How can I possibly do that? Hence I will be able to use the new function with only two arguments, but when called by the old name, will the new function be called ( because it is wrapped )?

How can I possibly do that?

Show source
| function   | python   | python-3.x   | wrapper   | wrap   2017-01-05 05:01 1 Answers

Answers ( 1 )

  1. 2017-01-05 05:01

    Once you have newFunction(x,y) defined you can redefine oldFunction as:

    def oldFunction(x,y,z):
        return newFunction(x,z)
◀ Go back