I wanted to write a class function which takes Signal object as a parameter and returns its copy. Then I wanted to overload this function with an instance function that returns copy of self argument. I have a following code:
def copy(cls, arg):
if not isinstance(arg, Signal):
raise ValueError("Argument must be of type Signal")
result = Signal()
result.framerate = arg.framerate
Signal1 = Signal(100)
Signal2 = signal1.copy()
Do I properly use python function overloading mechanism?
You can't have two functions with the same name; Python does not support overloading based on the types of the arguments. The definition of the second function will override that of the first.
In essence you're calling the non
copy over and over again. You'll need to rename one of these in order to get it to work effectively.
How can I pass *this argument to a class function within my class?
I'm guessing you mean
self here; passing
self to another function is done as with any other arg (as you did
FragmentsSignal.copy(self)). Your issue is that you're getting stumped by the recursion caused by the similar names.