Reputation: 278
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.
I want to create a new function which does exactly the same thing, with only the first and the third argument.
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 do that?
Upvotes: 2
Views: 137
Reputation: 608
Why not use keyword arguments? This way you could have both:
def function(a, b, c=None):
pass
And you can call it function(a, b)
and also function(a, b, c)
.
Upvotes: 0
Reputation: 51998
Once you have newFunction(x,y)
defined you can redefine oldFunction
as:
def oldFunction(x,y,z):
return newFunction(x,z)
Upvotes: 2