From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 4F3dB3e7AV83LQAA0tVLHw (envelope-from ) for ; Sun, 05 Jul 2020 11:37:27 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id ONGTA3e7AV9CDQAAB5/wlQ (envelope-from ) for ; Sun, 05 Jul 2020 11:37:27 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3C98994004E for ; Sun, 5 Jul 2020 11:37:26 +0000 (UTC) Received: from localhost ([::1]:59078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1js2xZ-0005Ba-6T for larch@yhetil.org; Sun, 05 Jul 2020 07:37:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqE9R-0006PR-77 for emacs-orgmode@gnu.org; Tue, 30 Jun 2020 07:10:09 -0400 Received: from forward105p.mail.yandex.net ([2a02:6b8:0:1472:2741:0:8b7:108]:41699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqE9N-0007N7-6J for emacs-orgmode@gnu.org; Tue, 30 Jun 2020 07:10:08 -0400 Received: from forward100q.mail.yandex.net (forward100q.mail.yandex.net [IPv6:2a02:6b8:c0e:4b:0:640:4012:bb97]) by forward105p.mail.yandex.net (Yandex) with ESMTP id 033EA4D410DE for ; Tue, 30 Jun 2020 14:09:59 +0300 (MSK) Received: from mxback8q.mail.yandex.net (mxback8q.mail.yandex.net [IPv6:2a02:6b8:c0e:42:0:640:b38f:32ec]) by forward100q.mail.yandex.net (Yandex) with ESMTP id 009957080004 for ; Tue, 30 Jun 2020 14:09:59 +0300 (MSK) Received: from vla5-e763f15c6769.qloud-c.yandex.net (vla5-e763f15c6769.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:e763:f15c]) by mxback8q.mail.yandex.net (mxback/Yandex) with ESMTP id 92WFLEzC8P-9wC8epVw; Tue, 30 Jun 2020 14:09:58 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crabman.me; s=mail; t=1593515398; bh=8U2w9sbK4caMxg+6T1sS7cuzul+NJruGv6ENdv0HEw0=; h=Subject:From:To:Date:Message-ID; b=WlW3SNDDyvspFl6XM6Ulsof1iZIPrAfgVqpm83VR/Ohd4JzXpxSQl+Pzb8lFrXMlZ uwMLiXThnZyPPHc4QIjTUOGS3ZSN8lDAaKYvtAmhFsJkps/ReSYaGz60JfrSu/hujZ 1YlFT+JDeelXbUSQr0BvXWuuyQQkmvHQANwayMMg= Received: by vla5-e763f15c6769.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id mKLqRCs5ka-9vlSZRLM; Tue, 30 Jun 2020 14:09:58 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) To: emacs-orgmode@gnu.org From: Philip Blagoveschensky Subject: Bug: org-babel python with :results value sends function definition with a statement after a for loop to the shell incorrectly [9.3.6 (9.3.6-elpa @ /home/username/.emacs.d/elpa/org-9.3.6/)] Message-ID: Date: Tue, 30 Jun 2020 14:09:56 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: none client-ip=2a02:6b8:0:1472:2741:0:8b7:108; envelope-from=philip@crabman.me; helo=forward105p.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 07:09:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Mailman-Approved-At: Sun, 05 Jul 2020 07:35:39 -0400 X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=crabman.me header.s=mail header.b=WlW3SNDD; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -0.21 X-TUID: QOZ9Jo5WimCt Consider the following org-babel block: #+begin_src python :session bug_report def foobar(): for i in range(5): pass print "hello world" foobar() #+end_src When I run it, this is what I see in the *bug_report* buffer: def foobar(): ... for i in range(5): ... pass ... >>> print "hello world" File "", line 1 print "hello world" ^ IndentationError: unexpected indent >>> foobar() >>> >>> open('/tmp/babel-MOOCF9/python-UW5PEF', 'w').write(str(_)) >>> >>> >>> 'org_babel_python_eoe' >>> 'org_babel_python_eoe' >>> So, org-babel incorrectly decided that the line with the print is not a part of the function's definition and sent it to Python shell as a separate statement. Instead, it should've sent it as a part of foobar's definition. This problem persists - If I use python3 instead of python2 - If I replace print "hello world" with return 42 This problem disappears if I add :results output to the source block. Emacs : GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.5) of 2019-09-23, modified by Debian Package: Org mode version 9.3.6 (9.3.6-elpa @ /home/username/.emacs.d/elpa/org-9.3.6/) current state: ============== (setq org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-configure-edit-buffer) org-link-shell-confirm-function 'yes-or-no-p org-metadown-hook '(org-babel-pop-to-session-maybe) org-clock-out-hook '(org-clock-remove-empty-clock-drawer) org-mode-hook '(#[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-show-all append local] 5] #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-babel-show-result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes) org-archive-hook '(org-attach-archive-delete-maybe) org-confirm-elisp-link-function 'yes-or-no-p org-agenda-before-write-hook '(org-agenda-add-entry-text) org-metaup-hook '(org-babel-load-in-session-maybe) org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn ENTRY)"] org-babel-pre-tangle-hook '(save-buffer) org-tab-first-hook '(org-babel-hide-result-toggle-maybe org-babel-header-arg-expand) org-babel-load-languages '((emacs-lisp . t) (python . t)) org-occur-hook '(org-first-headline-recenter) org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-show-empty-lines org-optimize-window-after-visibility-change) org-speed-command-hook '(org-speed-command-activate org-babel-speed-command-activate) org-babel-tangle-lang-exts '(("python" . "py") ("emacs-lisp" . "el") ("elisp" . "el")) org-confirm-shell-link-function 'yes-or-no-p org-link-parameters '(("attachment" :follow org-attach-open-link :export org-attach-export-link :complete org-attach-complete-link) ("id" :follow org-id-open) ("eww" :follow eww :store org-eww-store-link) ("rmail" :follow org-rmail-open :store org-rmail-store-link) ("mhe" :follow org-mhe-open :store org-mhe-store-link) ("irc" :follow org-irc-visit :store org-irc-store-link :export org-irc-export) ("info" :follow org-info-open :export org-info-export :store org-info-store-link) ("gnus" :follow org-gnus-open :store org-gnus-store-link) ("docview" :follow org-docview-open :export org-docview-export :store org-docview-store-link) ("bibtex" :follow org-bibtex-open :store org-bibtex-store-link) ("bbdb" :follow org-bbdb-open :export org-bbdb-export :complete org-bbdb-complete-link :store org-bbdb-store-link) ("w3m" :store org-w3m-store-link) ("file+sys") ("file+emacs") ("shell" :follow org-link--open-shell) ("news" :follow #[257 "\301\300\302Q!\207" ["news" browse-url ":"] 5 "\n\n(fn URL)"] ) ("mailto" :follow #[257 "\301\300\302Q!\207" ["mailto" browse-url ":"] 5 "\n\n(fn URL)"] ) ("https" :follow #[257 "\301\300\302Q!\207" ["https" browse-url ":"] 5 "\n\n(fn URL)"] ) ("http" :follow #[257 "\301\300\302Q!\207" ["http" browse-url ":"] 5 "\n\n(fn URL)"] ) ("ftp" :follow #[257 "\301\300\302Q!\207" ["ftp" browse-url ":"] 5 "\n\n(fn URL)"] ) ("help" :follow org-link--open-help) ("file" :complete org-link-complete-file) ("elisp" :follow org-link--open-elisp) ("doi" :follow org-link--open-doi)) org-link-elisp-confirm-function 'yes-or-no-p )