Skip to content

Commit 62eb1d5

Browse files
committed
pep8 for axiom and sympy interfaces
1 parent f10820f commit 62eb1d5

File tree

2 files changed

+121
-63
lines changed

2 files changed

+121
-63
lines changed

src/sage/interfaces/axiom.py

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ def _commands(self):
317317
i = s.find(start)
318318
end = "To get more information about"
319319
j = s.find(end)
320-
s = s[i+len(start):j].split()
321-
return s
320+
return s[i + len(start):j].split()
322321

323322
def _tab_completion(self, verbose=True, use_disk_cache=True):
324323
"""
@@ -357,15 +356,15 @@ def _tab_completion(self, verbose=True, use_disk_cache=True):
357356
print("To force rebuild later, delete %s." % self._COMMANDS_CACHE)
358357
v = self._commands()
359358

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

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

370369
self.__tab_completion = names
371370
if len(v) > 200:
@@ -430,7 +429,7 @@ def _eval_line(self, line, reformat=True, allow_use_file=False,
430429
if self._expect is None:
431430
self._start()
432431
if allow_use_file and self.__eval_using_file_cutoff and \
433-
len(line) > self.__eval_using_file_cutoff:
432+
len(line) > self.__eval_using_file_cutoff:
434433
return self._eval_line_using_file(line)
435434
try:
436435
E = self._expect
@@ -458,14 +457,14 @@ def _eval_line(self, line, reformat=True, allow_use_file=False,
458457
return out
459458
# out = out.lstrip()
460459
i = out.find('\n')
461-
out = out[i+1:]
460+
out = out[i + 1:]
462461
outs = out.split("\n")
463462
i = 0
464463
for line in outs:
465464
line = line.rstrip()
466465
if line[:4] == ' (':
467466
i = line.find('(')
468-
i += line[i:].find(')')+1
467+
i += line[i:].find(')') + 1
469468
if line[i:] == "":
470469
i = 0
471470
outs = outs[1:]
@@ -598,14 +597,13 @@ def _richcmp_(self, other, op):
598597
sage: f = axiom('sin(x)'); g = axiom('cos(x)') #optional - axiom
599598
sage: f == g #optional - axiom
600599
False
601-
602600
"""
603601
P = self.parent()
604-
if 'true' in P.eval("(%s = %s) :: Boolean" % (self.name(),other.name())):
602+
if 'true' in P.eval("(%s = %s) :: Boolean" % (self.name(), other.name())):
605603
return rich_to_bool(op, 0)
606604
elif 'true' in P.eval("(%s < %s) :: Boolean" % (self.name(), other.name())):
607605
return rich_to_bool(op, -1)
608-
elif 'true' in P.eval("(%s > %s) :: Boolean" % (self.name(),other.name())):
606+
elif 'true' in P.eval("(%s > %s) :: Boolean" % (self.name(), other.name())):
609607
return rich_to_bool(op, 1)
610608

611609
return NotImplemented
@@ -622,7 +620,7 @@ def type(self):
622620
P = self._check_valid()
623621
s = P._eval_line(self.name())
624622
i = s.rfind('Type:')
625-
return P(s[i+5:].strip())
623+
return P(s[i + 5:].strip())
626624

627625
def __len__(self):
628626
"""
@@ -637,7 +635,7 @@ def __len__(self):
637635
P = self._check_valid()
638636
s = P.eval('# %s ' % self.name())
639637
i = s.rfind('Type')
640-
return int(s[:i-1])
638+
return int(s[:i - 1])
641639

642640
def __getitem__(self, n):
643641
r"""
@@ -709,12 +707,12 @@ def _latex_(self):
709707
i = s.find('$$')
710708
j = s.rfind('$$')
711709
s = s[i + 2:j]
712-
s = multiple_replace({'\r':'', '\n':' ',
713-
' \\sp ':'^',
714-
'\\arcsin ':'\\sin^{-1} ',
715-
'\\arccos ':'\\cos^{-1} ',
716-
'\\arctan ':'\\tan^{-1} '},
717-
re.sub(r'\\leqno\(.*?\)','',s)) # no eq number!
710+
s = multiple_replace({'\r': '', '\n': ' ',
711+
' \\sp ': '^',
712+
'\\arcsin ': '\\sin^{-1} ',
713+
'\\arccos ': '\\cos^{-1} ',
714+
'\\arctan ': '\\tan^{-1} '},
715+
re.sub(r'\\leqno\(.*?\)', '', s)) # no eq number!
718716
return s
719717

720718
def as_type(self, type):
@@ -753,16 +751,13 @@ def unparsed_input_form(self):
753751
s = P.eval('unparse(%s::InputForm)' % self._name)
754752
if 'translation error' in s or 'Cannot convert' in s:
755753
raise NotImplementedError
756-
s = multiple_replace({'\r\n':'', # fix stupid Fortran-ish
757-
'DSIN(':'sin(',
758-
'DCOS(':'cos(',
759-
'DTAN(':'tan(',
760-
'DSINH(':'sinh('}, s)
761-
r = re.search(r'"(.*)"',s)
762-
if r:
763-
return r.groups(0)[0]
764-
else:
765-
return s
754+
s = multiple_replace({'\r\n': '', # fix stupid Fortran-ish
755+
'DSIN(': 'sin(',
756+
'DCOS(': 'cos(',
757+
'DTAN(': 'tan(',
758+
'DSINH(': 'sinh('}, s)
759+
r = re.search(r'"(.*)"', s)
760+
return r.groups(0)[0] if r else s
766761

767762
def _sage_(self):
768763
"""
@@ -835,8 +830,8 @@ def _sage_(self):
835830
from sage.rings.integer_ring import ZZ
836831
prec = max(self.mantissa().length()._sage_(), 53)
837832
R = RealField(prec)
838-
x,e,b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',')
839-
return R(ZZ(x)*ZZ(b)**ZZ(e))
833+
x, e, b = self.unparsed_input_form().lstrip('float(').rstrip(')').split(',')
834+
return R(ZZ(x) * ZZ(b)**ZZ(e))
840835
elif type == "DoubleFloat":
841836
from sage.rings.real_double import RDF
842837
return RDF(repr(self))
@@ -850,16 +845,18 @@ def _sage_(self):
850845
R = PolynomialRing(base_ring, vars)
851846
return R(self.unparsed_input_form())
852847
elif type.startswith('Fraction'):
853-
return self.numer().sage()/self.denom().sage()
848+
return self.numer().sage() / self.denom().sage()
854849

855-
#If all else fails, try using the unparsed input form
850+
# If all else fails, try using the unparsed input form
856851
try:
857852
import sage.misc.sage_eval
858853
vars = sage.symbolic.ring.var(str(self.variables())[1:-1])
859-
if isinstance(vars,tuple):
860-
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(), locals={str(x):x for x in vars})
854+
if isinstance(vars, tuple):
855+
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
856+
locals={str(x): x for x in vars})
861857
else:
862-
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(), locals={str(vars):vars})
858+
return sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),
859+
locals={str(vars): vars})
863860
except Exception:
864861
raise NotImplementedError
865862

@@ -961,9 +958,10 @@ def is_AxiomElement(x):
961958
return isinstance(x, AxiomElement)
962959

963960

964-
#Instances
961+
# Instances
965962
axiom = Axiom(name='axiom')
966963

964+
967965
def reduce_load_Axiom():
968966
"""
969967
Returns the Axiom interface object defined in
@@ -977,6 +975,7 @@ def reduce_load_Axiom():
977975
"""
978976
return axiom
979977

978+
980979
def axiom_console():
981980
"""
982981
Spawn a new Axiom command-line session.

0 commit comments

Comments
 (0)