Subject: bug#32390:

From: Carlos Pita <[email-masked]>
Date: Tue, 7 Aug 2018 16:10:24 -0300

The buffer is indeed being cleaned up in the output filter:

(defun python-shell-font-lock-comint-output-filter-function (output)
  (if (and (not (string= "" output))
      ...
      (python-shell-font-lock-cleanup-buffer)

The problem is that an unclosed string is an error and in that case
output is "", so that the cleanup part is not reached. I think it
should be made unconditional.