0

I recently saw this code in an open source project:

def download(self, system, version, target=None, verbose=False):

    #
    # [some code]
    #

    return download(system, version, target, verbose=verbose)

The return statement above is the only one in this function. There is not base case or anything like that.

Please can anyone explain what is actually happening here. How can a function return itself?

Vincent Savard
  • 34,979
  • 10
  • 68
  • 73
  • 4
    They look like different functions. One takes `self` as a parameter (i.e. a method) and one doesn't. – Vincent Savard Feb 04 '16 at 13:29
  • 3
    The method https://github.com/dronekit/dronekit-sitl/blob/master/dronekit_sitl/__init__.py#L131 calls the function https://github.com/dronekit/dronekit-sitl/blob/master/dronekit_sitl/__init__.py#L91 That they have the same name might be confusing but those names exist in different scopes. – Dan D. Feb 04 '16 at 13:32
  • If I remember correctly, functions with `self` in their parameters usually means that they're inside a class. Correct me if I am wrong. – Sean Francis N. Ballais Feb 04 '16 at 13:37
  • You are partly right. Methods with `self` can only be called within an instanced object. But you can define functions within a class which take `cls` or nothing as parameter. This is described at http://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod-in-python. – wewa Feb 04 '16 at 13:49
  • `download(self,...)` suggests it's a method of some class. `download(system,...)` may be a "free floating" function that comes from elsewhere. I'd look at imports in this file, if there's something like `from xyz import download` or maybe a `download` function resides in another module and it is imported via unrecommended practice `from xyz import *` – LetMeSOThat4U Feb 04 '16 at 15:46

0 Answers0