We are developing a python library and would like to change the way some function arguments are named in some functions.
We would like to keep backward compatibility and thus we would like to find a way to create alias for function arguments.
Here is an example:
Old Version:
class MyClass(object):
def __init__(self, object_id):
self.id = object_id
New Version:
class MyClass(object):
def __init__(self, id_object):
self.id = id_object
How can we make the class to be compatible with both calling ways:
object1 = MyClass(object_id=1234)
object2 = MyClass(id_object=1234)
I could of course create something like this:
class MyClass(object):
def __init__(self, object_id=None, id_object=None):
if id_object is not None:
self.id = id_object
else:
self.id = object_id
However, it would change the number of arguments and we strictly want to avoid this.
Is there any way to declare a method alias or an argument alias ?