I know Python doesn't support overloading, but I'm not sure how to do the following task in Python without resorting to different method names.
I have two methods which require different set of parameters:
def get_infobox_from_list(templates):
for template in templates:
if get_base_length(template[0]) >= 0:
return template
return None
def get_infobox(site, name):
# first try box template
infobox = get_infobox_from_list(get_templates(site, "{}/Box".format(name)))
if infobox is None:
infobox = get_infobox_from_list(get_templates(site, name))
return infobox
Both methods do similar things (they get you a template), but their parameters are different. Now I've read that Python is usually allowing this by using default arguments.
That might be helping sometimes, but the difference is, that the method either needs two parameters (site and name) or one (templates) but no other combination (like site and templates, only name, only site, name and templates or all three).
Now in Java I could simply define those two overloading methods. So if somebody is calling either one of them their parameters must match without defining to many or to few. So my question is, how should it be done in Python really.
get_infobox_frominget_infoboxsupposed to be calls toget_infobox_from_list, or isget_infobox_fromyet another related function that's kicking around? Assuming the former, I'd probably renameget_infobox_from_listanyway in this example. It returns the first thing from its input whose length is non-negative, I don't see that its name necessarily needs to be anything to do withinfobox. Call itfind_usable_templateor something.get_base_lengthfunction does return basically what type of infobox it is. If it returns a negative value, the checked template isn't anything the program can understand. And I missspelledget_infobox_from, it should beget_infobox_from_list.