I have the variable r of type dict. Variable item holds a list of items, and total_results is an int. As long as the condition is met that the number of items is less than the total amount of items, the function is called recursively. However, if I test whether the items are equal to the total results, the return statement returns None. Changing this elif to if does return the correct value.
Could someone point me into the right direction to find out why returning r yields None in the elif or else block?
Many thanks !!
Relevant code snippet:
if len(items) < total_results:
    params['start_index'] = len(items)
    self.fetch_company_officers(company_number=company_number, items=items, **params)
elif len(items) == total_results:
    r['items'] = items
    return r
Full code:
def fetch_company_officers(self, company_number, items=None, **kwargs):
    uri = 'company/{}/officers'.format(company_number)
    params = kwargs
    r = self.make_request(uri=uri, **params)
    # Test if items are set
    if items is None:
        items = r['items']
    else:
        items.extend(r['items'])
    # Iterate multiple pages
    total_results = r['total_results']
    if len(items) < total_results:
        params['start_index'] = len(items)
        self.fetch_company_officers(company_number=company_number, items=items, **params)
    elif len(items) == total_results: # TO DO: ??
        r['items'] = items
        return r
 
    