I think it would be better to work on a copy of the initial `gsn`, because it can be confusing for the creator of the original `gsn` if its `type` changes.
Adding `gsn = copy.copy(gsn)` at the beginning would probably be enough.