Preventing floods while saving logs I had a logging function…

@task
def log_request(label, target, request_as_dict):
    # Detect flood

    # In general this task do not process misuse. But it can send
    # an alarm to another celery task if something strange happened.
    if incr_with_ttl(INDICATOR_KEY, INDICATOR_TTL) &gt;= INDICATOR_THRESHOLD:
        process_misuse.apply_async()
        redis.delete(INDICATOR_KEY)

    # Save entry
    fields = request_as_dict['fields']
    fields.update({
        "label": label,
        "type": 1 if target else 2, # 1: target, 2: extra

        "suspicion": suspicion_rating(request_as_dict),
        "raw_request": request_as_dict
    })
    RequestEntry.objects.create(**fields)


… that I rewrote using two inner functions for readability.

@task
def log_request(label, target, request_as_dict):

    def detect_flood():
        '''
        In general this task do not process misuse. But it can send
        an alarm to another celery task if something strange happened.
        '''
        if incr_with_ttl(INDICATOR_KEY, INDICATOR_TTL) &gt;= INDICATOR_THRESHOLD:
            process_misuse.apply_async()
            redis.delete(INDICATOR_KEY)

    def save_entry():
        fields = request_as_dict['fields']
        fields.update({
            "label": label,
            "type": 1 if target else 2, # 1: target, 2: extra

            "suspicion": suspicion_rating(request_as_dict),
            "raw_request": request_as_dict
        })
        RequestEntry.objects.create(**fields)

    save_entry()
    detect_flood()


Is the rewrite an improvement?
Yes this is fine. 

By the single responsibility principle, and to achieve functional cohesion, a function should do one thing. As the responsibility of this function takes two logical steps, it makes sense to move those steps to their own functions. And since these functions are only used once, and so they would not be useful not desirable in the global namespace, it makes sense to hide them as inner functions.