From e5262923b61e88bce605b25be54f391e3a2afa8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 27 Mar 2022 21:24:45 +0200 Subject: [PATCH] clean the mathics.py file --- src/sage/interfaces/kenzo.py | 4 +-- src/sage/interfaces/mathics.py | 48 ++++++++++++++-------------------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/sage/interfaces/kenzo.py b/src/sage/interfaces/kenzo.py index 7fc8ce6c537..e005b5b6832 100644 --- a/src/sage/interfaces/kenzo.py +++ b/src/sage/interfaces/kenzo.py @@ -24,14 +24,12 @@ # https://www.gnu.org/licenses/ # **************************************************************************** - from sage.structure.sage_object import SageObject from sage.homology.homology_group import HomologyGroup from sage.rings.integer_ring import ZZ from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup from sage.groups.abelian_gps.abelian_group import AbelianGroup from sage.categories.commutative_additive_groups import CommutativeAdditiveGroups -from sage.groups.additive_abelian.additive_abelian_group import AdditiveAbelianGroup from sage.matrix.constructor import matrix from sage.homology.chain_complex import ChainComplex @@ -1879,7 +1877,7 @@ def build_morphism(source_complex, target_complex, degree, algorithm, strategy, """ return KenzoChainComplexMorphism( __build_mrph_aux__(source_complex._kenzo, target_complex._kenzo, - degree, algorithm, ":"+strategy, orgn)) + degree, algorithm, ":" + strategy, orgn)) def morphism_dictmat(morphism): diff --git a/src/sage/interfaces/mathics.py b/src/sage/interfaces/mathics.py index 207fd4e3182..c65eaa2e103 100644 --- a/src/sage/interfaces/mathics.py +++ b/src/sage/interfaces/mathics.py @@ -381,13 +381,11 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ ############################################################################## import os -import re -from enum import Enum from sage.misc.cachefunc import cached_method from sage.interfaces.interface import Interface, InterfaceElement, InterfaceFunction, InterfaceFunctionElement from sage.interfaces.tab_completion import ExtraTabCompletion @@ -395,7 +393,6 @@ from sage.structure.richcmp import rich_to_bool - def _mathics_sympysage_symbol(self): r""" Convert a Sympy symbol ``self`` to a correspondig element @@ -515,7 +512,6 @@ def _start(self): from sage.interfaces.sympy import sympy_init sympy_init() from sympy import Symbol - from sympy.core.relational import Relational Symbol._sage_ = _mathics_sympysage_symbol def _read_in_file_command(self, filename): @@ -531,7 +527,7 @@ def _read_in_file_command(self, filename): sage: os.system('rm %s' %fn) # optional - mathics 0 """ - return '<<"%s"'%filename + return '<<"%s"' % filename def _install_hints(self): """ @@ -547,7 +543,6 @@ def _install_hints(self): optional Sage package Mathics installed. """ - def _eval(self, code): """ Evaluates a command inside the Mathics interpreter and returns the output @@ -575,13 +570,12 @@ def eval(self, code, *args, **kwds): sage: mathics.eval('1+1') # optional - mathics '2' """ - res= self._eval(code) + res = self._eval(code) if res.result == 'Null': if len(res.out) == 1: return str(res.out[0]) return res.result - def set(self, var, value): """ Set the variable var to the given value. @@ -592,8 +586,8 @@ def set(self, var, value): sage: bool(mathics('u').sage() == 2*x+e) # optional - mathics True """ - cmd = '%s=%s;'%(var,value) - out = self.eval(cmd) + cmd = '%s=%s;' % (var, value) + _ = self.eval(cmd) def get(self, var): """ @@ -616,7 +610,7 @@ def _function_call_string(self, function, args, kwds): sage: mathics._function_call_string('Sin', ['x'], []) 'Sin[x]' """ - return "%s[%s]"%(function, ",".join(args)) + return "%s[%s]" % (function, ",".join(args)) def _left_list_delim(self): r""" @@ -654,10 +648,9 @@ def _right_func_delim(self): """ return "]" - - ########################################### + # ######################################### # System -- change directory, etc - ########################################### + # ######################################### def chdir(self, dir): """ Change Mathics's current working directory. @@ -668,7 +661,7 @@ def chdir(self, dir): sage: mathics('Directory[]') # optional - mathics / """ - self.eval('SetDirectory["%s"]'%dir) + self.eval('SetDirectory["%s"]' % dir) def _true_symbol(self): r""" @@ -806,9 +799,9 @@ def help(self, cmd, long=False): """ if long: - return self.eval('Information[%s]' %cmd) + return self.eval('Information[%s]' % cmd) else: - return self.eval('? %s' %cmd) + return self.eval('? %s' % cmd) def __getattr__(self, attrname): r""" @@ -889,7 +882,6 @@ def _tab_completion(self): """ return dir(self._mathics_result.last_eval) - def __getitem__(self, n): r""" EXAMPLES:: @@ -902,7 +894,7 @@ def __getitem__(self, n): x 0.15 """ - return self.parent().new('%s[[%s]]'%(self._name, n)) + return self.parent().new('%s[[%s]]' % (self._name, n)) def __getattr__(self, attrname): r""" @@ -936,7 +928,7 @@ def __float__(self, precision=16): True """ P = self.parent() - return float(P._eval('N[%s,%s]'%(self.name(), precision)).last_eval.to_mpmath()) + return float(P._eval('N[%s,%s]' % (self.name(), precision)).last_eval.to_mpmath()) def _reduce(self): r""" @@ -967,9 +959,9 @@ def _latex_(self): sage: latex(Q) # optional - mathics \frac{\text{Sin}\left[x \text{Cos}\left[y\right]\right]}{\sqrt{1-x^2}} """ - z = str(self.parent()('TeXForm[%s]'%self.name())) + z = str(self.parent()('TeXForm[%s]' % self.name())) i = z.find('=') - return z[i+1:] + return z[i + 1:] def _repr_(self): r""" @@ -1132,7 +1124,7 @@ def save_image(self, filename, ImageSize=600): if not self._is_graphics(): raise ValueError('mathics expression is not graphics') filename = os.path.abspath(filename) - s = 'Export["%s", %s, ImageSize->%s]'%(filename, self.name(), ImageSize) + s = 'Export["%s", %s, ImageSize->%s]' % (filename, self.name(), ImageSize) P.eval(s) def _rich_repr_(self, display_manager, **kwds): @@ -1201,7 +1193,6 @@ def show(self, ImageSize=600): dm = get_display_manager() dm.display_immediately(self, ImageSize=ImageSize) - def _richcmp_(self, other, op): r""" EXAMPLES:: @@ -1217,11 +1208,11 @@ def _richcmp_(self, other, op): False """ P = self.parent() - if str(P("%s < %s"%(self.name(), other.name()))) == P._true_symbol(): + if str(P("%s < %s" % (self.name(), other.name()))) == P._true_symbol(): return rich_to_bool(op, -1) - elif str(P("%s > %s"%(self.name(), other.name()))) == P._true_symbol(): + elif str(P("%s > %s" % (self.name(), other.name()))) == P._true_symbol(): return rich_to_bool(op, 1) - elif str(P("%s == %s"%(self.name(), other.name()))) == P._true_symbol(): + elif str(P("%s == %s" % (self.name(), other.name()))) == P._true_symbol(): return rich_to_bool(op, 0) return NotImplemented @@ -1270,6 +1261,7 @@ def n(self, *args, **kwargs): # An instance mathics = Mathics() + def reduce_load(X): """ Used in unpickling a Mathics element.