 	;; at a non-zero nesting level.  It may be slow for people who
 	;; write huge code blocks or huge lists ... tough beans.
 	(re-search-backward py-parse-state-re nil 'move)
+	;; Watch out for landing inside a list comprehension
+	(save-excursion
+	  (if (and (looking-at "[ \t]*\\<\\(if\\|for\\)\\>")
+		   (py-safe (progn (up-list -1) t))
+		   (eq (char-after) ?\[))
+	      (setq in-listcomp (point))
+	    (setq in-listcomp nil)))
 	(beginning-of-line)
 	;; In XEmacs, we have a much better way to test for whether
 	;; we're in a triple-quoted string or not.  Emacs does not

  "Return the parse state at point (see `parse-partial-sexp' docs)."
  (save-excursion
    (let ((here (point))
	  pps done)
      (while (not done)
	;; back up to the first preceding line (if any; else start of
	;; buffer) that begins with a popular Python keyword, or a

	  ;; XEmacs
	  (setq done (or (not (buffer-syntactic-context))
			 (bobp)))
	  (when in-listcomp
	    (goto-char in-listcomp)
	    (setq done nil))
	  (when done
	    (setq pps (parse-partial-sexp (point) here)))
	  ))
