From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6Dc2O15dBF+ZXQAA0tVLHw (envelope-from ) for ; Tue, 07 Jul 2020 11:32:46 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id AMANN15dBF9ZAgAA1q6Kng (envelope-from ) for ; Tue, 07 Jul 2020 11:32:46 +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 A10D294004E for ; Tue, 7 Jul 2020 11:32:43 +0000 (UTC) Received: from localhost ([::1]:51842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jslq6-00018C-56 for larch@yhetil.org; Tue, 07 Jul 2020 07:32:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jslpU-000165-6J for emacs-orgmode@gnu.org; Tue, 07 Jul 2020 07:32:04 -0400 Received: from mail-ej1-f45.google.com ([209.85.218.45]:35091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jslpS-0006iM-84 for emacs-orgmode@gnu.org; Tue, 07 Jul 2020 07:32:03 -0400 Received: by mail-ej1-f45.google.com with SMTP id rk21so46209817ejb.2 for ; Tue, 07 Jul 2020 04:31:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hM2BI5YatHdcca6tK+30UjzBIsak4/gh3bMhCp9ar4M=; b=nQE7QYsvCug6hib3spDUydpKJ0zQ4UcbyduVnxJqVkQmAAvfbkoVqGUPQ7J5Vk5r8Q nKWPNo5ldVfg5TDhXe56AtoPdO2x1Enh0RGD2Ab7qktmRxNqaTd3QY3Y3BtntNBv1OX+ zHWQ/epPg74Ghh9nPUrLUj8ypbGZA3x05N8oAqo/mVVyD3eEwc7K7FKiv3XIl7jIa0D4 TrElYMUK+6x++r1XvZqjQ1/7gfwy7laQVyreGpCIt+tuGl0z/QTFlT21guVHxH8xALsL myXjxyJBjoAan2z3LPmJZ8YXx/vxJLVnMlTjYIKh4lbrigN0N+HjgQDzBH9TlT6l50Zz C/Ig== X-Gm-Message-State: AOAM532toEU1YOcK+BSbe4Df66Q56+Nm4tdGvwUtDbqOT1Zd4sXabUoa uwTbpFuUl8Sqot0qRxZraSXmB0T8T9R8CLreewo= X-Google-Smtp-Source: ABdhPJwOv50WE0nRQqezknLMHpJtkAactrKF5ELpofvAp5q7UGSGUmXhAlahMh1MuRSQy++8zp7DNIzBQQePiiA97N8= X-Received: by 2002:a17:907:4240:: with SMTP id oi24mr45875566ejb.23.1594121517245; Tue, 07 Jul 2020 04:31:57 -0700 (PDT) MIME-Version: 1.0 References: <5c1caa08-6c08-ebb9-ee81-76143c3a60b2@crabman.me> In-Reply-To: <5c1caa08-6c08-ebb9-ee81-76143c3a60b2@crabman.me> From: ian martins Date: Tue, 7 Jul 2020 07:31:45 -0400 Message-ID: Subject: Re: 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: Philip Blagoveschensky Content-Type: multipart/alternative; boundary="000000000000c3aeb005a9d8567d" Received-SPF: pass client-ip=209.85.218.45; envelope-from=ianxm1@gmail.com; helo=mail-ej1-f45.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/07 07:31:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 3 X-Spam_score: 0.3 X-Spam_bar: / X-Spam_report: (0.3 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-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: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=jhu.edu (policy=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.91 X-TUID: nxh3FseYA/XC --000000000000c3aeb005a9d8567d Content-Type: text/plain; charset="UTF-8" I was able to reproduce the error. I started emacs without my init file (emacs -q) and then ,---- | (add-to-list 'load-path "~/code/elisp/org-mode/lisp") | (require 'ob-python) | (org-babel-do-load-languages 'org-babel-load-languages `((python . t))) `---- in scratch, and then ran your test. I got the same errors you described. I redid the test but loaded the lastest org-mode and there was no error. This means you probably don't need to debug this. It has been fixed in the latest version, but the fix hasn't been updated in the elpa package yet. you can either wait for the next release or pull the latest code from the repo. On Mon, Jul 6, 2020 at 3:18 PM Philip Blagoveschensky wrote: > Hi Ian, > > >Do you have the same issue if you aren't using a session? > > If I run the following code block (this time I am using python 3, so > there are parens in the print line) > > #+begin_src python > def foobar(): > for i in range(5): > pass > print("hello world") > return 3 > > return foobar() > #+end_src > > I get > > #+RESULTS: > : 3 > > so I know it worked fine. > > But if I add session like this: > > #+begin_src python :session bug_report > def foobar(): > for i in range(5): > pass > print("hello world") > return 3 > > return foobar() > #+end_src > > then in *bug_report* I get > > >>> def foobar(): > ... for i in range(5): > ... pass > ... > >>> print("hello world") > File "", line 1 > print("hello world") > ^ > IndentationError: unexpected indent > return 3 > >>> > File "", line 1 > return 3 > ^ > IndentationError: unexpected indent > >>> return foobar() > >>> > File "", line 1 > SyntaxError: 'return' outside function > >>> open('/tmp/babel-D0mRnD/python-CJ6UtT', 'w').write(str(_)) > >>> > 20 > >>> > >>> 'org_babel_python_eoe' > >>> 'org_babel_python_eoe' > >>> > > >Are you using tabs or spaces? > > I used spaces. 4 spaces per indentation level, to be exact. > > Also, FYI, as it might be relevant information, the shell buffer > contents I posted above happen if the session has been created > previously. If, instead, this is the first time I run some code in this > session, then I also get another error - NameError (see below). Below > you can see the contents of *bug_report* buffer if I run this code cell > in a not-yet-existing session. > > def foobar(): > Python 3.8.2 | packaged by conda-forge | (default, Mar 5 2020, 17:11:00) > [GCC 7.3.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> ... for i in range(5): > ... pass > ... > >>> print("hello world") > File "", line 1 > print("hello world") > ^ > IndentationError: unexpected indent return 3 > > >>> > File "", line 1 > return 3 > ^ > IndentationError: unexpected indent > >>> return foobar() > >>> > File "", line 1 > SyntaxError: 'return' outside function > >>> open('/tmp/babel-D0mRnD/python-MsDjEk', 'w').write(str(_)) > >>> > Traceback (most recent call last): > File "", line 1, in > NameError: name '_' is not defined > >>> > >>> 'org_babel_python_eoe' > >>> 'org_babel_python_eoe' > >>> > > If you have a suggestion on how to debug this, feel free to tell. > --000000000000c3aeb005a9d8567d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I was able to reproduce the error. I started emacs wi= thout my init file (emacs -q) and then

,----<= br>| (add-to-list 'load-path "~/code/elisp/org-mode/lisp")| (require 'ob-python)
| (org-babel-do-load-languages 'org-babe= l-load-languages `((python . t)))
`----

in = scratch, and then ran your test. I got the same errors you described. I red= id the test but loaded the lastest org-mode and there was no error. This me= ans you probably don't need to debug this. It has been fixed in the lat= est version, but the fix hasn't been updated in the elpa package yet. y= ou can either wait for the next release or pull the latest code from the re= po.

On Mon, Jul 6, 2020 at 3:18 PM Philip Blagoveschensky <philip@crabman.me> wrote:
Hi Ian,

=C2=A0>Do you have the same issue if you aren't using a session?

If I run the following code block (this time I am using python 3, so
there are parens in the print line)

#+begin_src python
def foobar():
=C2=A0 =C2=A0 =C2=A0for i in range(5):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pass
=C2=A0 =C2=A0 =C2=A0print("hello world")
=C2=A0 =C2=A0 =C2=A0return 3

return foobar()
#+end_src

I get

#+RESULTS:
: 3

so I know it worked fine.

But if I add session like this:

#+begin_src python :session bug_report
def foobar():
=C2=A0 =C2=A0 =C2=A0for i in range(5):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pass
=C2=A0 =C2=A0 =C2=A0print("hello world")
=C2=A0 =C2=A0 =C2=A0return 3

return foobar()
#+end_src

then in *bug_report* I get

=C2=A0>>> def foobar():
...=C2=A0 =C2=A0 =C2=A0for i in range(5):
...=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pass
...
=C2=A0>>>=C2=A0 =C2=A0 =C2=A0print("hello world")
=C2=A0 =C2=A0File "<stdin>", line 1
=C2=A0 =C2=A0 =C2=A0print("hello world")
=C2=A0 =C2=A0 =C2=A0^
IndentationError: unexpected indent
=C2=A0 =C2=A0 =C2=A0return 3
=C2=A0>>>
=C2=A0 =C2=A0File "<stdin>", line 1
=C2=A0 =C2=A0 =C2=A0return 3
=C2=A0 =C2=A0 =C2=A0^
IndentationError: unexpected indent
=C2=A0>>> return foobar()
=C2=A0>>>
=C2=A0 =C2=A0File "<stdin>", line 1
SyntaxError: 'return' outside function
=C2=A0>>> open('/tmp/babel-D0mRnD/python-CJ6UtT', 'w&#= 39;).write(str(_))
=C2=A0>>>
20
=C2=A0>>>
=C2=A0>>> 'org_babel_python_eoe'
=C2=A0>>> 'org_babel_python_eoe'
=C2=A0>>>

=C2=A0>Are you using tabs or spaces?

I used spaces. 4 spaces per indentation level, to be exact.

Also, FYI, as it might be relevant information, the shell buffer
contents I posted above happen if the session has been created
previously. If, instead, this is the first time I run some code in this session, then I also get another error - NameError (see below). Below
you can see the contents of *bug_report* buffer if I run this code cell in a not-yet-existing session.

def foobar():
Python 3.8.2 | packaged by conda-forge | (default, Mar=C2=A0 5 2020, 17:11:= 00)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "= license" for more information.
=C2=A0>>> ...=C2=A0 =C2=A0 =C2=A0for i in range(5):
...=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pass
...
=C2=A0>>>=C2=A0 =C2=A0 =C2=A0print("hello world")
=C2=A0 =C2=A0File "<stdin>", line 1
=C2=A0 =C2=A0 =C2=A0print("hello world")
=C2=A0 =C2=A0 =C2=A0^
IndentationError: unexpected indent=C2=A0 =C2=A0 return 3

=C2=A0>>>
=C2=A0 =C2=A0File "<stdin>", line 1
=C2=A0 =C2=A0 =C2=A0return 3
=C2=A0 =C2=A0 =C2=A0^
IndentationError: unexpected indent
=C2=A0>>> return foobar()
=C2=A0>>>
=C2=A0 =C2=A0File "<stdin>", line 1
SyntaxError: 'return' outside function
=C2=A0>>> open('/tmp/babel-D0mRnD/python-MsDjEk', 'w&#= 39;).write(str(_))
=C2=A0>>>
Traceback (most recent call last):
=C2=A0 =C2=A0File "<stdin>", line 1, in <module>
NameError: name '_' is not defined
=C2=A0>>>
=C2=A0>>> 'org_babel_python_eoe'
=C2=A0>>> 'org_babel_python_eoe'
=C2=A0>>>

If you have a suggestion on how to debug this, feel free to tell.
--000000000000c3aeb005a9d8567d--