From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oO0yMH/A/F7dAQAA0tVLHw (envelope-from ) for ; Wed, 01 Jul 2020 16:57:35 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id yBE8K3/A/F4vdgAAbx9fmQ (envelope-from ) for ; Wed, 01 Jul 2020 16:57:35 +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 C6A929403EE for ; Wed, 1 Jul 2020 16:57:34 +0000 (UTC) Received: from localhost ([::1]:43722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqg3B-0003N8-Ny for larch@yhetil.org; Wed, 01 Jul 2020 12:57:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqg1R-0001fy-Fp for emacs-orgmode@gnu.org; Wed, 01 Jul 2020 12:55:45 -0400 Received: from forward102o.mail.yandex.net ([37.140.190.182]:33470) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqg1O-0005qz-Bt for emacs-orgmode@gnu.org; Wed, 01 Jul 2020 12:55:45 -0400 Received: from mxback10o.mail.yandex.net (mxback10o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::24]) by forward102o.mail.yandex.net (Yandex) with ESMTP id 0D2A966800BC for ; Wed, 1 Jul 2020 19:55:37 +0300 (MSK) Received: from sas1-e00c2743cdb8.qloud-c.yandex.net (sas1-e00c2743cdb8.qloud-c.yandex.net [2a02:6b8:c14:3a22:0:640:e00c:2743]) by mxback10o.mail.yandex.net (mxback/Yandex) with ESMTP id pcPmWmoOzD-taeGbS7T; Wed, 01 Jul 2020 19:55:37 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crabman.me; s=mail; t=1593622537; bh=zXX68+cLntrySox8oqok8Qi2VCJ4oO1f7m5bI5xrk9g=; h=To:Subject:From:Date:Message-ID; b=cVOdQw8dbHkE8gYVDP4OsdEbRjvcTgfuNN2M8gp6OJFluXMVK6JlldR983TX3qhL6 znHPHu7836dIDevjKxFyqgVwTbFyXdUWJ2KvDErk74Y1oo1qW2uo2hra7t4mXuXase 4jqxDTopAz51dA+ErVGSV6URIvbAX0CXIE7And+s= Received: by sas1-e00c2743cdb8.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id GqNrqOdQrA-tZkes8Sl; Wed, 01 Jul 2020 19:55:36 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) 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/)] To: emacs-orgmode@gnu.org Message-ID: <294a8a24-c899-7fc5-5c3d-03fe7b487292@crabman.me> Date: Wed, 1 Jul 2020 19:55:34 +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=37.140.190.182; envelope-from=philip@crabman.me; helo=forward102o.mail.yandex.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/01 12:55:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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=cVOdQw8d; 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: -1.21 X-TUID: xiMUjGr240Is 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 )