You avoid the in-place by doing
out = out + residual
You can verify that with other data structures as well:
a = []
b = a # b is the same as a
a += [5]
print(b) # prints [5]
# now
a = []
b = a # b is the same as a
a = a + [5]
print(b) # prints []