Skip to content

Commit ca0624a

Browse files
author
Release Manager
committed
gh-36745: pep8 for axiom and sympy interfaces pep8 cleanup for the 2 modified files ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. URL: #36745 Reported by: Frédéric Chapoton Reviewer(s): Kwankyu Lee, Matthias Köppe
2 parents dea7789 + 8d8b28d commit ca0624a

File tree

2 files changed

+119
-61
lines changed

2 files changed

+119
-61
lines changed

src/sage/interfaces/axiom.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ def _commands(self):
318318
i = s.find(start)
319319
end = "To get more information about"
320320
j = s.find(end)
321-
s = s[i+len(start):j].split()
322-
return s
321+
return s[i + len(start):j].split()
323322

324323
def _tab_completion(self, verbose=True, use_disk_cache=True):
325324
"""
@@ -359,15 +358,15 @@ def _tab_completion(self, verbose=True, use_disk_cache=True):
359358
print("To force rebuild later, delete %s." % self._COMMANDS_CACHE)
360359
v = self._commands()
361360

362-
#Process we now need process the commands to strip out things which
363-
#are not valid Python identifiers.
361+
# Process we now need process the commands to strip out things which
362+
# are not valid Python identifiers.
364363
valid = re.compile('[^a-zA-Z0-9_]+')
365364
names = [x for x in v if valid.search(x) is None]
366365

367-
#Change everything that ends with ? to _q and
368-
#everything that ends with ! to _e
369-
names += [x[:-1]+"_q" for x in v if x.endswith("?")]
370-
names += [x[:-1]+"_e" for x in v if x.endswith("!")]
366+
# Change everything that ends with ? to _q and
367+
# everything that ends with ! to _e
368+
names += [x[:-1] + "_q" for x in v if x.endswith("?")]
369+
names += [x[:-1] + "_e" for x in v if x.endswith("!")]
371370

372371
self.__tab_completion = names
373372
if len(v) > 200:
@@ -433,7 +432,7 @@ def _eval_line(self, line, reformat=True, allow_use_file=False,
433432
if self._expect is None:
434433
self._start()
435434
if allow_use_file and self.__eval_using_file_cutoff and \
436-
len(line) > self.__eval_using_file_cutoff:
435+
len(line) > self.__eval_using_file_cutoff:
437436
return self._eval_line_using_file(line)
438437
try:
439438
E = self._expect
@@ -468,7 +467,7 @@ def _eval_line(self, line, reformat=True, allow_use_file=False,
468467
line = line.rstrip()
469468
if line[:4] == ' (':
470469
i = line.find('(')
471-
i += line[i:].find(')')+1
470+
i += line[i:].find(')') + 1
472471
if line[i:] == "":
473472
i = 0
474473
outs = outs[1:]
@@ -603,14 +602,13 @@ def _richcmp_(self, other, op):
603602
sage: f = axiom('sin(x)'); g = axiom('cos(x)') #optional - axiom
604603
sage: f == g #optional - axiom
605604
False
606-
607605
"""
608606
P = self.parent()
609-
if 'true' in P.eval("(%s = %s) :: Boolean" % (self.name(),other.name())):
607+
if 'true' in P.eval("(%s = %s) :: Boolean" % (self.name(), other.name())):
610608
return rich_to_bool(op, 0)
611609
elif 'true' in P.eval("(%s < %s) :: Boolean" % (self.name(), other.name())):
612610
return rich_to_bool(op, -1)
613-
elif 'true' in P.eval("(%s > %s) :: Boolean" % (self.name(),other.name())):
611+
elif 'true' in P.eval("(%s > %s) :: Boolean" % (self.name(), other.name())):
614612
return rich_to_bool(op, 1)
615613

616614
return NotImplemented
@@ -642,7 +640,7 @@ def __len__(self):
642640
P = self._check_valid()
643641
s = P.eval('# %s ' % self.name())
644642
i = s.rfind('Type')
645-
return int(s[:i-1])
643+
return int(s[:i - 1])
646644

647645
def __getitem__(self, n):
648646
r"""
@@ -716,12 +714,12 @@ def _latex_(self):
716714
i = s.find('$$')
717715
j = s.rfind('$$')
718716
s = s[i + 2:j]
719-
s = multiple_replace({'\r':'', '\n':' ',
720-
' \\sp ':'^',
721-
'\\arcsin ':'\\sin^{-1} ',
722-
'\\arccos ':'\\cos^{-1} ',
723-
'\\arctan ':'\\tan^{-1} '},
724-
re.sub(r'\\leqno\(.*?\)','',s)) # no eq number!
717+
s = multiple_replace({'\r': '', '\n': ' ',
718+
' \\sp ': '^',
719+
'\\arcsin ': '\\sin^{-1} ',
720+
'\\arccos ': '\\cos^{-1} ',
721+
'\\arctan ': '\\tan^{-1} '},
722+
re.sub(r'\\leqno\(.*?\)', '', s)) # no eq number!
725723
return s
726724

727725
def as_type(self, type):
@@ -760,16 +758,13 @@ def unparsed_input_form(self):
760758
s = P.eval('unparse(%s::InputForm)' % self._name)
761759
if 'translation error' in s or 'Cannot convert' in s:
762760
raise NotImplementedError
763-
s = multiple_replace({'\r\n':'', # fix stupid Fortran-ish
764-
'DSIN(':'sin(',
765-
'DCOS(':'cos(',
766-
'DTAN(':'tan(',
767-
'DSINH(':'sinh('}, s)
768-
r = re.search(r'"(.*)"',s)
769-
if r:
770-
return r.groups(0)[0]
771-
else:
772-
return s
761+
s = multiple_replace({'\r\n': '', # fix stupid Fortran-ish
762+
'DSIN(': 'sin(',
763+
'DCOS(': 'cos(',
764+
'DTAN(': 'tan(',
765+
'DSINH(': 'sinh('}, s)
766+
r = re.search(r'"(.*)"', s)
767+
return r.groups(0)[0] if r else s
773768

774769
def _sage_(self):
775770
"""
@@ -843,8 +838,8 @@ def _sage_(self):
843838
from sage.rings.integer_ring import ZZ
844839
prec = max(self.mantissa().length()._sage_(), 53)
845840
R = RealField(prec)
846-
x,e,b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',')
847-
return R(ZZ(x)*ZZ(b)**ZZ(e))
841+
x, e, b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',')
842+
return R(ZZ(x) * ZZ(b)**ZZ(e))
848843
elif type == "DoubleFloat":
849844
from sage.rings.real_double import RDF
850845
return RDF(repr(self))
@@ -858,16 +853,18 @@ def _sage_(self):
858853
R = PolynomialRing(base_ring, vars)
859854
return R(self.unparsed_input_form())
860855
elif type.startswith('Fraction'):
861-
return self.numer().sage()/self.denom().sage()
856+
return self.numer().sage() / self.denom().sage()
862857

863-
#If all else fails, try using the unparsed input form
858+
# If all else fails, try using the unparsed input form
864859
try:
865860
import sage.misc.sage_eval
866861
vars = sage.symbolic.ring.var(str(self.variables())[1:-1])
867-
if isinstance(vars,tuple):
868-
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(), locals={str(x):x for x in vars})
862+
if isinstance(vars, tuple):
863+
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
864+
locals={str(x): x for x in vars})
869865
else:
870-
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(), locals={str(vars):vars})
866+
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
867+
locals={str(vars): vars})
871868
except Exception:
872869
raise NotImplementedError
873870

@@ -970,9 +967,10 @@ def is_AxiomElement(x):
970967
return isinstance(x, AxiomElement)
971968

972969

973-
#Instances
970+
# Instances
974971
axiom = Axiom(name='axiom')
975972

973+
976974
def reduce_load_Axiom():
977975
"""
978976
Returns the Axiom interface object defined in
@@ -986,6 +984,7 @@ def reduce_load_Axiom():
986984
"""
987985
return axiom
988986

987+
989988
def axiom_console():
990989
"""
991990
Spawn a new Axiom command-line session.

0 commit comments

Comments
 (0)