From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oN4WAey8fV/GVQAA0tVLHw (envelope-from ) for ; Wed, 07 Oct 2020 13:04:44 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id EKZ6OOu8fV/mQwAAbx9fmQ (envelope-from ) for ; Wed, 07 Oct 2020 13:04:43 +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 95168940631 for ; Wed, 7 Oct 2020 13:04:40 +0000 (UTC) Received: from localhost ([::1]:48504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ97W-00014n-En for larch@yhetil.org; Wed, 07 Oct 2020 09:04:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPukn-0001GY-EA for emacs-orgmode@gnu.org; Tue, 06 Oct 2020 17:44:13 -0400 Received: from scc-mailout-kit-02.scc.kit.edu ([2a00:1398:9:f712::810d:e752]:38088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPukk-0003Eu-7m for emacs-orgmode@gnu.org; Tue, 06 Oct 2020 17:44:13 -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=cf8R6YjmA+63B8uJNq3dszNUq9Dgv5N8ZbN/lZ8PSnc=; b=A5k6qtaT3cgEyMApp1RuN+/UD/ E4+In0ESdB3b5AReWH0Y2mw+92yJ+ft8bOeq27TShH7Q0622cNWj40fPSd9JZlWJk0fuEUxpTGZrc 6YWVG5Fr7k92ea/8qgEpHs1LagcfhzUx5ds0KIb8rJIG/8Xg2AcfXHrykpbNVv3ljLaU=; Received: from kit-msx-45.kit.edu ([2a00:1398:9:f612::145]) by scc-mailout-kit-02.scc.kit.edu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (envelope-from ) id 1kPukb-0008GC-5G for emacs-orgmode@gnu.org; Tue, 06 Oct 2020 23:44:02 +0200 Received: from localhost (2a02:8071:229c:5200::2) 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; Tue, 6 Oct 2020 23:44:00 +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: Tue, 6 Oct 2020 23:44:00 +0200 Message-ID: <87mu0zav33.fsf@student.kit.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Originating-IP: [2a02:8071:229c:5200::2] Received-SPF: pass client-ip=2a00:1398:9:f712::810d:e752; envelope-from=adrian.kummerlaender@student.kit.edu; helo=scc-mailout-kit-02.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-Mailman-Approved-At: Wed, 07 Oct 2020 09:02:56 -0400 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=A5k6qtaT; 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: 0.09 X-TUID: HmpA0z5iOpCM --=-=-= 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 wishes, 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 --=-=-=--