Ihor Radchenko <yanta...@posteo.net> writes: > I'm afraid that trying to replicate Python REPL behavior for > non-interactive src blocks will be beyond what we can reasonably do in > Org: we would somehow need to detect the last statement in the src > blocks, which may or may not span a single line; and multiline statements > will need to use some kind of Python parser. All this sounds way too > fragile to be practical.
Well, ob-python sessions implement this sort of parser in `org-babel-python-format-session-value', which AFAIK is robust. I think it would be feasible to switch non-session blocks to use this parser, which IMO is nicer behavior -- the "return" statements always felt weird to me. But a major reason not to do it is to avoid breaking compatibility. Lots of old ob-python nonsession blocks with "return" statements out there. But perhaps we could implement an option to switch nonsession value to the session value behavior (omitting "return"). The default behavior should remain unchanged (requiring "return"), but in the long term we could consider changing the default if there is consensus for it. (I likely don't have bandwidth to implement such an option in the near term, but would be supportive if anyone wants to have a go at it).