When you change/edit code, you have to consider some implications:
- Maybe the way the code is posted IS the real problem and by changing it you obscure the problem.
- The questioner maybe using the same libraries that you use, but in a different way, either allowed or disallowed. Editing that may again obscure the problem, or conflict with the initial intentions of the author.
- In case of an answer, It may be malformed but that will render it a bad answer. You can comment on that and the author can edit it as he thinks suitable.
In your specific case, if you read just above the authors code, he states that he only pasted the relevant (in his opinion) code from a link that he provided in his answer.
As a (strictly) personal rule of thumb, I touch on code only to make it more readable (code posted as one line, code block between
`
and not in an actual block etc.). I do not even mess with indentation most of the time, because in languages like Python, that matters as well.
It is better to comment on the intentions of an author when you spot potentially malformed code.