Skip to content

Commit 3c2ba82

Browse files
author
Release Manager
committed
gh-35530: some minor details in interfaces <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description Just using iterators in some join ; removing a very simple function used only once ; a few other minor details <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35530 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 12cea80 + 27ac965 commit 3c2ba82

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

src/sage/interfaces/axiom.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,13 @@ def comma(self, *args):
684684
[2,3,4]
685685
sage: _.type() #optional - axiom
686686
Tuple PositiveInteger
687-
688687
"""
689688
P = self._check_valid()
690689
args = list(args)
691690
for i, arg in enumerate(args):
692691
if not isinstance(arg, AxiomElement) or arg.parent() is not P:
693692
args[i] = P(arg)
694-
cmd = "(" + ",".join([x.name() for x in [self]+args]) + ")"
693+
cmd = "(" + ",".join(x.name() for x in [self] + args) + ")"
695694
return P(cmd)
696695

697696
def _latex_(self):

src/sage/interfaces/expect.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
- François Bissey, Bill Page, Jeroen Demeyer (2015-12-09): Upgrade to
2929
pexpect 4.0.1 + patches, see :trac:`10295`.
3030
"""
31-
3231
# ****************************************************************************
3332
# Copyright (C) 2005 William Stein <[email protected]>
3433
#
@@ -38,7 +37,6 @@
3837
# (at your option) any later version.
3938
# https://www.gnu.org/licenses/
4039
# ****************************************************************************
41-
4240
import io
4341
import os
4442
import re
@@ -219,7 +217,7 @@ def set_server_and_command(self, server=None, command=None, server_tmpdir=None,
219217

220218
def server(self):
221219
"""
222-
Returns the server used in this interface.
220+
Return the server used in this interface.
223221
224222
EXAMPLES::
225223
@@ -232,7 +230,7 @@ def server(self):
232230

233231
def command(self):
234232
"""
235-
Returns the command used in this interface.
233+
Return the command used in this interface.
236234
237235
EXAMPLES::
238236
@@ -1082,11 +1080,11 @@ def interrupt(self, tries=5, timeout=2.0, quit_on_fail=True):
10821080
# BEGIN Synchronization code.
10831081
###########################################################################
10841082

1085-
def _before(self, encoding=None, errors=None):
1083+
def _before(self, encoding=None, errors=None) -> str:
10861084
r"""
10871085
Return the previous string that was sent through the interface.
10881086
1089-
Returns ``str`` objects on both Python 2 and Python 3.
1087+
This returns a ``str`` object.
10901088
10911089
The ``encoding`` and ``errors`` arguments are passed to
10921090
:func:`sage.misc.cpython.bytes_to_str`.
@@ -1126,7 +1124,7 @@ def _after(self, encoding=None, errors=None):
11261124

11271125
return after
11281126

1129-
def _readline(self, size=-1, encoding=None, errors=None):
1127+
def _readline(self, size=-1, encoding=None, errors=None) -> str:
11301128
r"""
11311129
Wraps ``spawn.readline`` to pass the return values through
11321130
``bytes_to_str``, like `Expect._before` and `Expect._after`.
@@ -1139,7 +1137,6 @@ def _readline(self, size=-1, encoding=None, errors=None):
11391137
sage: singular._readline()
11401138
'2\r\n'
11411139
"""
1142-
11431140
return bytes_to_str(self._expect.readline(size=size), encoding, errors)
11441141

11451142
def _interrupt(self):
@@ -1166,12 +1163,10 @@ def _expect_expr(self, expr=None, timeout=None):
11661163
11671164
INPUT:
11681165
1169-
1170-
- ``expr`` - None or a string or list of strings
1166+
- ``expr`` -- None or a string or list of strings
11711167
(default: None)
11721168
1173-
- ``timeout`` - None or a number (default: None)
1174-
1169+
- ``timeout`` -- None or a number (default: None)
11751170
11761171
EXAMPLES:
11771172
@@ -1345,7 +1340,6 @@ def eval(self, code, strip=True, synchronize=False, locals=None, allow_use_file=
13451340
"""
13461341
INPUT:
13471342
1348-
13491343
- ``code`` -- text to evaluate
13501344
13511345
- ``strip`` -- bool; whether to strip output prompts,
@@ -1393,8 +1387,8 @@ def eval(self, code, strip=True, synchronize=False, locals=None, allow_use_file=
13931387
self._eval_using_file_cutoff and len(code) > self._eval_using_file_cutoff):
13941388
return self._eval_line_using_file(code)
13951389
elif split_lines:
1396-
return '\n'.join([self._eval_line(L, allow_use_file=allow_use_file, **kwds)
1397-
for L in code.split('\n') if L != ''])
1390+
return '\n'.join(self._eval_line(L, allow_use_file=allow_use_file, **kwds)
1391+
for L in code.split('\n') if L)
13981392
else:
13991393
return self._eval_line(code, allow_use_file=allow_use_file, **kwds)
14001394
# DO NOT CATCH KeyboardInterrupt, as it is being caught
@@ -1512,7 +1506,9 @@ def __init__(self, parent, value, is_name=False, name=None):
15121506

15131507
def __hash__(self):
15141508
"""
1515-
Returns the hash of self. This is a default implementation of hash
1509+
Return the hash of self.
1510+
1511+
This is a default implementation of hash
15161512
which just takes the hash of the string of self.
15171513
"""
15181514
return hash('%s%s' % (self, self._session_number))
@@ -1544,7 +1540,7 @@ def __del__(self):
15441540
if P is not None:
15451541
P.clear(self._name)
15461542

1547-
except (RuntimeError, ExceptionPexpect): # needed to avoid infinite loops in some rare cases
1543+
except (RuntimeError, ExceptionPexpect): # needed to avoid infinite loops in some rare cases
15481544
pass
15491545

15501546
# def _sage_repr(self):
@@ -1563,11 +1559,11 @@ def __init__(self, interface, silent=False, stdout=None):
15631559
15641560
INPUT:
15651561
1566-
- ``interface`` - the interface whose communication shall be dumped.
1562+
- ``interface`` -- the interface whose communication shall be dumped.
15671563
1568-
- ``silent`` - if ``True`` this context does nothing
1564+
- ``silent`` -- if ``True`` this context does nothing
15691565
1570-
- ``stdout`` - optional parameter for alternative stdout device (default: ``None``)
1566+
- ``stdout`` -- optional parameter for alternative stdout device (default: ``None``)
15711567
15721568
EXAMPLES::
15731569
@@ -1621,7 +1617,3 @@ def __exit__(self, typ, value, tb):
16211617
self.interface._expect.logfile.flush()
16221618
self.stdout.write("\n")
16231619
self.interface._expect.logfile = self._logfile_backup
1624-
1625-
1626-
def console(cmd):
1627-
os.system(cmd)

src/sage/interfaces/fricas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def get_string(self, var):
711711
We test that strings are returned properly::
712712
713713
sage: r = fricas.get_string('concat([concat(string(i)," ") for i in 0..299])') # optional - fricas
714-
sage: r == " ".join([str(i) for i in range(300)]) + ' ' # optional - fricas
714+
sage: r == " ".join(str(i) for i in range(300)) + ' ' # optional - fricas
715715
True
716716
717717
sage: fricas.get_string('concat([string(1) for i in 1..5])') == "1"*5 # optional - fricas

src/sage/interfaces/magma.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,15 @@
209209
#
210210
# The full text of the GPL is available at:
211211
#
212-
# http://www.gnu.org/licenses/
212+
# https://www.gnu.org/licenses/
213213
# ****************************************************************************
214214
from __future__ import annotations
215215
import re
216216
import sys
217+
import os
217218

218219
from sage.structure.parent import Parent
219-
from .expect import console, Expect, ExpectElement, ExpectFunction, FunctionElement
220+
from .expect import Expect, ExpectElement, ExpectFunction, FunctionElement
220221
PROMPT = ">>>"
221222

222223
SAGE_REF = "_sage_ref"
@@ -252,7 +253,6 @@ def extcode_dir(iface=None):
252253
shutil.copytree('%s/magma/' % SAGE_EXTCODE, tmp + '/data')
253254
EXTCODE_DIR = "%s/data/" % tmp
254255
else:
255-
import os
256256
tmp = iface._remote_tmpdir()
257257
command = 'scp -q -r "%s/magma/" "%s:%s/data" 1>&2 2>/dev/null' % (SAGE_EXTCODE, iface._server, tmp)
258258
try:
@@ -330,7 +330,6 @@ def __init__(self, script_subdirectory=None,
330330
Magma
331331
"""
332332
if command is None:
333-
import os
334333
command = os.getenv('SAGE_MAGMA_COMMAND') or 'magma'
335334

336335
if not user_config:
@@ -339,7 +338,6 @@ def __init__(self, script_subdirectory=None,
339338
# Obtain the parameters from the environment, to allow the magma = Magma() phrase
340339
# to work with non-default parameters.
341340
if seed is None:
342-
import os
343341
seed = os.getenv('SAGE_MAGMA_SEED')
344342

345343
Expect.__init__(self,
@@ -2787,7 +2785,7 @@ def magma_console():
27872785
from sage.repl.rich_output.display_manager import get_display_manager
27882786
if not get_display_manager().is_in_terminal():
27892787
raise RuntimeError('Can use the console only in the terminal. Try %%magma magics instead.')
2790-
console('magma')
2788+
os.system('magma')
27912789

27922790

27932791
class MagmaGBLogPrettyPrinter:

0 commit comments

Comments
 (0)