Skip to content

Commit 1f16443

Browse files
KnairdAjackkamm
authored andcommitted
ob-python: Rename exec tmpfile handle to prevent conflict
* lisp/ob-python.el (org-babel-python--exec-tmpfile): Rename tmpfile handle (org-babel-python-format-session-value): Rename tmpfile handle Opening the exec tmpfile as a `f' variable shadows any such variable that might by defined by the Python session context. e.g. my Org babel files commonly pass single letter variables inside a session which is broken by this behavior. The new name `__org_babel_python_tmpfile' is in line with other org mode specific Python variables set by ob-python. This is unlikely to conflict with the user's Python code. TINYCHANGE
1 parent 23f9415 commit 1f16443

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lisp/ob-python.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def main():
244244
open('%s', 'w').write( pprint.pformat(main()) )")
245245

246246
(defconst org-babel-python--exec-tmpfile "\
247-
with open('%s') as f:
248-
exec(compile(f.read(), f.name, 'exec'))"
247+
with open('%s') as __org_babel_python_tmpfile:
248+
exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))"
249249
"Template for Python session command with output results.
250250
251251
Has a single %s escape, the tempfile containing the source code
@@ -256,20 +256,20 @@ to evaluate.")
256256
"Return Python code to evaluate SRC-FILE and write result to RESULT-FILE."
257257
(format "\
258258
import ast
259-
with open('%s') as f:
260-
__org_babel_python_ast = ast.parse(f.read())
259+
with open('%s') as __org_babel_python_tmpfile:
260+
__org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read())
261261
__org_babel_python_final = __org_babel_python_ast.body[-1]
262262
if isinstance(__org_babel_python_final, ast.Expr):
263263
__org_babel_python_ast.body = __org_babel_python_ast.body[:-1]
264264
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
265265
__org_babel_python_final = eval(compile(ast.Expression(
266266
__org_babel_python_final.value), '<string>', 'eval'))
267-
with open('%s', 'w') as f:
267+
with open('%s', 'w') as __org_babel_python_tmpfile:
268268
if %s:
269269
import pprint
270-
f.write(pprint.pformat(__org_babel_python_final))
270+
__org_babel_python_tmpfile.write(pprint.pformat(__org_babel_python_final))
271271
else:
272-
f.write(str(__org_babel_python_final))
272+
__org_babel_python_tmpfile.write(str(__org_babel_python_final))
273273
else:
274274
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
275275
__org_babel_python_final = None"

0 commit comments

Comments
 (0)