From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KMn6LA5gfV8lLQAA0tVLHw (envelope-from ) for ; Wed, 07 Oct 2020 06:28:30 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id SG3bKA5gfV9pCAAAB5/wlQ (envelope-from ) for ; Wed, 07 Oct 2020 06:28:30 +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 EC22F9400EF for ; Wed, 7 Oct 2020 06:28:29 +0000 (UTC) Received: from localhost ([::1]:55964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ2w8-0004DI-4t for larch@yhetil.org; Wed, 07 Oct 2020 02:28:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ2vZ-0004DB-1n for emacs-orgmode@gnu.org; Wed, 07 Oct 2020 02:27:53 -0400 Received: from scc-mailout-kit-01.scc.kit.edu ([2a00:1398:9:f712::810d:e751]:56058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ2vR-0003jX-UX for emacs-orgmode@gnu.org; Wed, 07 Oct 2020 02:27:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=student.kit.edu; s=20190212; h=Content-Type:MIME-Version:Message-ID:Date: Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OO5LZ3bXkeFL4BDauQMywR1xjK4nU+LFqKKoqy+TG8o=; b=bf0iqFYkIlT3oRNDC8Tj5OVtik U67ak8H1i3/R14HGpIqSJZ4gV9n/rMTQ/zAd60XGEBNNhGTmRaVjvD/KcoFYYVZdrpXRhcIqQRy0u qSCsT17KK3qxHPhwoj7n22Kx+78CemspcIE0+AU0ZdrSSCZq1aDqRmjyW1EZthYhlxyQ=; Received: from kit-msx-51.kit.edu ([2a00:1398:9:f612::151]) by scc-mailout-kit-01.scc.kit.edu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (envelope-from ) id 1kQ2vL-0005Ne-ND for emacs-orgmode@gnu.org; Wed, 07 Oct 2020 08:27:41 +0200 Received: from localhost (2a02:8071:229c:5200::3) by smtp.kit.edu (2a00:1398:9:f612::106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.659.4; Wed, 7 Oct 2020 08:27:38 +0200 User-agent: mu4e 1.2.0; emacs 28.0.50 From: Adrian =?utf-8?Q?Kummerl=C3=A4nder?= To: Subject: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict Date: Wed, 7 Oct 2020 08:27:33 +0200 Message-ID: <87pn5uzh2i.fsf@student.kit.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Originating-IP: [2a02:8071:229c:5200::3] Received-SPF: pass client-ip=2a00:1398:9:f712::810d:e751; envelope-from=adrian.kummerlaender@student.kit.edu; helo=scc-mailout-kit-01.scc.kit.edu X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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=fail (rsa verify failed) header.d=student.kit.edu header.s=20190212 header.b=bf0iqFYk; dmarc=fail reason="SPF not aligned (relaxed)" header.from=student.kit.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: 1.59 X-TUID: iQSyvj681p8R --=-=-= Content-Type: text/plain Hello, I noticed that after updating to Org 9.4 many of my Python-based Org files fail to execute with various `io.TextIOWrapper' related error messages. The reason for this is that opening the exec tmpfile as `f' shadows this possibly user-defined variable. The attached patch fixes this problem for me. As this is my first time contributing to Org I am especially open for any suggestions! Best regards, Adrian --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename="0001-ob-python-Rename-exec-tmpfile-handle-to-prevent-conf.patch" Content-Description: ob-python: Rename exec tmpfile handle to prevent conflict >From 239aa9aaa8da0f98719469abdff46ecb7a3994ba Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 6 Oct 2020 23:06:08 +0200 Subject: [PATCH] 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. --- lisp/ob-python.el | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 785b9191b..6752adc17 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -244,8 +244,8 @@ def main(): open('%s', 'w').write( pprint.pformat(main()) )") (defconst org-babel-python--exec-tmpfile "\ -with open('%s') as f: - exec(compile(f.read(), f.name, 'exec'))" +with open('%s') as __org_babel_python_tmpfile: + exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))" "Template for Python session command with output results. Has a single %s escape, the tempfile containing the source code @@ -256,20 +256,20 @@ to evaluate.") "Return Python code to evaluate SRC-FILE and write result to RESULT-FILE." (format "\ import ast -with open('%s') as f: - __org_babel_python_ast = ast.parse(f.read()) +with open('%s') as __org_babel_python_tmpfile: + __org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read()) __org_babel_python_final = __org_babel_python_ast.body[-1] if isinstance(__org_babel_python_final, ast.Expr): __org_babel_python_ast.body = __org_babel_python_ast.body[:-1] exec(compile(__org_babel_python_ast, '', 'exec')) __org_babel_python_final = eval(compile(ast.Expression( __org_babel_python_final.value), '', 'eval')) - with open('%s', 'w') as f: + with open('%s', 'w') as __org_babel_python_tmpfile: if %s: import pprint - f.write(pprint.pformat(__org_babel_python_final)) + __org_babel_python_tmpfile.write(pprint.pformat(__org_babel_python_final)) else: - f.write(str(__org_babel_python_final)) + __org_babel_python_tmpfile.write(str(__org_babel_python_final)) else: exec(compile(__org_babel_python_ast, '', 'exec')) __org_babel_python_final = None" -- 2.25.4 --=-=-=--