From 78db2fd007eae2b88f2ed695d8726b5f664504c6 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 17 Feb 2022 06:49:14 -0500 Subject: [PATCH] Trac #33213: close an open file a bit sooner in gap interface. (This is unrelated to the main goal of the ticket.) After reading the contents of a file using the "with open(...)" context manager, we now take the opportunity to close that file immediately by un-indenting the subsequent code to reside outside of the "with" block. --- src/sage/interfaces/gap.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/sage/interfaces/gap.py b/src/sage/interfaces/gap.py index 729e97965f5..f665acbbcfc 100644 --- a/src/sage/interfaces/gap.py +++ b/src/sage/interfaces/gap.py @@ -1298,22 +1298,22 @@ def help(self, s, pager=True): with io.open(self._local_tmpfile(), "r", encoding=gap_encoding) as fobj: help = fobj.read() - if pager: - from IPython.core.page import page - page(help, start=sline) - else: - # Find the n-th line and return from there - idx = -1 - while sline: - try: - idx = help.find('\n', idx + 1) - sline -= 1 - except ValueError: - # We ran out of lines early somehow; this shouldn't - # happen though - break - - return help[idx:] + if pager: + from IPython.core.page import page + page(help, start=sline) + else: + # Find the n-th line and return from there + idx = -1 + while sline: + try: + idx = help.find('\n', idx + 1) + sline -= 1 + except ValueError: + # We ran out of lines early somehow; this shouldn't + # happen though + break + + return help[idx:] def set(self, var, value): """