You can do the following:
(defun python-electric-pair-string-delimiter () (when (and electric-pair-mode (memq last-command-event '(?\" ?\')) (let ((count 0)) (while (eq (char-before (- (point) count)) last-command-event) (setq count (1+ count))) (= count 3))) (save-excursion (insert (make-string 3 last-command-event))))) (add-hook 'python-mode-hook (lambda () (add-hook 'post-self-insert-hook #'python-electric-pair-string-delimiter 'append t)))
It will be included in the next version of Emacs.
source share