I think you could refactor this to make the logic clearer.  In particular, I'm having trouble following the inner function that has side-effects.

It may be possible to simplify the logic here a bit by using a buffer to hold numbers that may or may not need to be combined.  For example:
```
# List to temporarily hold line numbers that we're not sure need to be combined
line_buffer = []

# Add a terminating value of `None` to handle the last element in the loop
for line_number in line_numbers + [None]:
     # If the current number is adjacent to the previous number
     if len(line_buffer) == 0 or (line_buffer[-1] + 1) == line_number:
          line_buffer.append(line_number)
     elif len(line_buffer) == 1:
          combined_set.append(str(line_buffer[0]))
     else:
          combined_set.append(combine_template.format(line_buffer[0], line_buffer[-1]))
```

I haven't tested the above code, so your mileage may vary.  But I think an approach like that would avoid the inner function without duplicating code.