A bit hard to guess without complete file, ideally in some format that preserves bytes exactly.
:1:40
refers to first line, char position 40. The line is 38 characters long.
Thus suspicion falls on newline marker.
Most likely newline (single char) is not recognised and Python (not flake8 btw) treats this line and the next and one long line. Thus error is in column 40.
Alternatively your newline is a sequence of 2 chars and 2nd char is not understood correctly.
There could theoretically also be an encoding problem, but I find that quite unlikely.