emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug: ob-python mangles multiline :var values [9.3.6 (release_9.3.6-3


From: Matthew Lundin
Subject: Re: Bug: ob-python mangles multiline :var values [9.3.6 (release_9.3.6-397-ga089600)]
Date: Wed, 27 May 2020 13:26:58 -0500

Jack Kamm <address@hidden> writes:

> Hello,
>
> Thanks for reporting. I've just fixed this issue in master (commit
> 6149b6cb6).
>
> The problem was that ob-python adds tab indentation to the code body
> before putting it inside a main() function, which adds spurious
> indentation to multiline strings passed through :var.
>
> I fixed the issue by moving variable assignment from the code body to
> the code preamble, which is executed outside the main() function.

A heads up... I believe this changes the scope of the :var variables,
since they previously were local to the main() function and now they are
declared globally. After this change, some of my existing python source
blocks (i.e., ones in which I attempt to assign a new value to a
variable defined by :var) now generate the following error:

Traceback (most recent call last):
  File "<stdin>", line 223, in <module>
  File "<stdin>", line 214, in main
UnboundLocalError: local variable 'members' referenced before assignment

I hesitate to call this a bug, since it would be fine to think of
everything within the source block as local and the header :var
declarations as global. But if this is the case, then I think it should
be documented somewhere, especially since this change may break people's
existing source blocks. And I suppose it would be worthwhile to ask: Is
this change consistent with other org-babel modules? Is there a
canonical way that org-babel handles scope?

Best,

Matt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]