diff --git a/.circleci/config.yml b/.circleci/config.yml index 2b8c4db5..bae4394b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,10 +62,6 @@ jobs: <<: *defaults docker: - image: circleci/python:3.5 - "python-2.7": - <<: *defaults - docker: - - image: circleci/python:2.7 "publish": docker: - image: circleci/python:3.7 @@ -89,7 +85,6 @@ workflows: only: /^v.*$/ - "python-3.6" - "python-3.5" - - "python-2.7" - publish: requires: - "python-3.7" diff --git a/.travis.yml b/.travis.yml index 94f08bef..f234d38e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: python matrix: include: - os: linux - python: '2.7' + python: '3.5' env: CONDA=true - os: linux python: '3.6' diff --git a/README.md b/README.md index b28efdbb..6585cad1 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Installing GAlgebra ### Prerequisites - Works on Linux, Windows, Mac OSX -- [Python](https://www.python.org/) 2.7 or >=3.5 +- [Python](https://www.python.org/) >=3.5 - [SymPy](https://www.sympy.org) 1.3, 1.4 or preferably 1.5 ### Installing GAlgebra From PyPI (Recommended for users) diff --git a/doc/python/BACCAB.py b/doc/python/BACCAB.py index 3461c03a..2f6df865 100644 --- a/doc/python/BACCAB.py +++ b/doc/python/BACCAB.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function from galgebra.printer import Format, xpdf from galgebra.ga import Ga diff --git a/doc/python/Dirac.py b/doc/python/Dirac.py index 17aa8b1b..3717b356 100644 --- a/doc/python/Dirac.py +++ b/doc/python/Dirac.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function import sys from sympy import symbols, sin, cos from galgebra.printer import Format, xpdf, Get_Program, Print_Function diff --git a/doc/python/Dop.py b/doc/python/Dop.py index ee666e21..0b8d187e 100644 --- a/doc/python/Dop.py +++ b/doc/python/Dop.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function from sympy import symbols, sin from galgebra.printer import Format, xpdf from galgebra.ga import Ga diff --git a/doc/python/EMWaves.py b/doc/python/EMWaves.py index 5035a57b..b0b680cd 100644 --- a/doc/python/EMWaves.py +++ b/doc/python/EMWaves.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function import sys from sympy import symbols, exp, I, Matrix, solve, simplify from galgebra.printer import Format, xpdf, Get_Program, Print_Function diff --git a/doc/python/LinearTrans.py b/doc/python/LinearTrans.py index f5f8180c..512b7dba 100644 --- a/doc/python/LinearTrans.py +++ b/doc/python/LinearTrans.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function from sympy import symbols, sin, cos from galgebra.ga import Ga from galgebra.printer import Format, xpdf diff --git a/doc/python/Ltrans.py b/doc/python/Ltrans.py index f0df9435..b2210498 100644 --- a/doc/python/Ltrans.py +++ b/doc/python/Ltrans.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function from sympy import symbols, sin, cos, latex from galgebra.ga import Ga from galgebra.printer import Format, xpdf diff --git a/doc/python/ReciprocalBasis.py b/doc/python/ReciprocalBasis.py index 495dbfa0..0cdeb596 100644 --- a/doc/python/ReciprocalBasis.py +++ b/doc/python/ReciprocalBasis.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function from sympy import expand, simplify from galgebra.printer import Format, xpdf from galgebra.ga import Ga diff --git a/doc/python/SphericalCoordinates.py b/doc/python/SphericalCoordinates.py index 1c4bc29b..c0abf5af 100644 --- a/doc/python/SphericalCoordinates.py +++ b/doc/python/SphericalCoordinates.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function import sys from sympy import symbols, sin from galgebra.printer import Format, xpdf diff --git a/doc/python/submanifold.py b/doc/python/submanifold.py index 35b8eb08..d78c6953 100644 --- a/doc/python/submanifold.py +++ b/doc/python/submanifold.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division -from __future__ import print_function from sympy import symbols, sin, pi, latex from galgebra.ga import Ga from galgebra.printer import Format, xpdf diff --git a/galgebra/__init__.py b/galgebra/__init__.py index 0d975537..026acdd5 100644 --- a/galgebra/__init__.py +++ b/galgebra/__init__.py @@ -20,6 +20,4 @@ utils """ -from __future__ import absolute_import, division -from __future__ import print_function from ._version import __version__ diff --git a/galgebra/deprecated.py b/galgebra/deprecated.py index 6efed748..db702357 100644 --- a/galgebra/deprecated.py +++ b/galgebra/deprecated.py @@ -3,7 +3,6 @@ from sympy import trigsimp, S from . import ga from .mv import Mv -from . import utils ################################# MV class for backward compatibility ################### @@ -23,7 +22,7 @@ def convert_metric(gstr): @staticmethod def setup(basis, metric=None, coords=None, rframe=False, debug=False, curv=(None,None)): - if utils.isstr(metric): + if isinstance(metric, str): metric = MV.convert_metric(metric) if curv != (None,None): MV.GA = ga.Ga(basis, g=None, coords=coords, X=curv[0], debug=debug) diff --git a/galgebra/ga.py b/galgebra/ga.py index eb2bdf60..c6489863 100644 --- a/galgebra/ga.py +++ b/galgebra/ga.py @@ -1,7 +1,6 @@ """ Geometric Algebra (inherits Metric) """ -import sys import warnings import operator import copy @@ -20,7 +19,6 @@ from . import metric from . import mv from . import lt -from . import utils half = Rational(1, 2) one = S(1) @@ -377,20 +375,24 @@ def __hash__(self): def __eq__(self, ga): return self.name == ga.name - if sys.version_info.major < 3: - def __ne__(self, other): - return not (self == other) - - def __init__(self, bases, **kwargs): + def __init__(self, bases, *, wedge=True, **kwargs): + """ + Parameters + ---------- + bases : + Passed as ``basis`` to ``Metric``. + wedge : + Use ``^`` symbol to print basis blades + **kwargs : + See :class:`galgebra.metric.Metric`. + """ # Each time a geometric algebra is intialized in setup of append # the printer must be restored to the simple text mode (not # enhanced text of latex printing) so that when 'str' is used to # create symbol names the names are not mangled. - kwargs = metric.test_init_slots(metric.Metric.init_slots, **kwargs) - - self.wedge_print = kwargs['wedge'] + self.wedge_print = wedge if printer.GaLatexPrinter.latex_flg: printer.GaLatexPrinter.restore() @@ -545,7 +547,7 @@ def mv(self, root=None, *args, **kwargs): # ensure that ga is not already in kwargs kwargs = dict(ga=self, **kwargs) - if not utils.isstr(root): + if not isinstance(root, str): return mv.Mv(root, *args, **kwargs) if ' ' in root and ' ' not in args[0]: @@ -1903,31 +1905,10 @@ class Sm(Ga): the coordinates of the submanifold. The inputs required to define the submanifold are: - Parameters - ---------- - u : - (``args[0]``) The coordinate map defining the submanifold - which is a list of functions of coordinates of the base - manifold in terms of the coordinates of the submanifold. - for example if the manifold is a unit sphere then - - ``u = [sin(u)*cos(v),sin(u)*sin(v),cos(u)]``. - - Alternatively (``args[0]``) is a parametric vector function - of the basis vectors of the base manifold. The - coefficients of the bases are functions of the coordinates - (``args[1]``). In this case we would call the submanifold - a "vector" manifold and additional characteristics of the - manifold can be calculated since we have given an explicit - embedding of the manifold in the base manifold. - - coords : - (``args[1]``) The coordinate list for the submanifold, for - example ``[u, v]``. - Notes ----- - See 'init_slots' for possible other inputs. The 'Ga' member function + The 'Ga' member function 'sm' can be used to instantiate the submanifold via (o3d is the base manifold):: @@ -1937,13 +1918,40 @@ class Sm(Ga): (eu,ev) = sm_example.mv() sm_grad = sm_example.grad """ - init_slots = {'debug': (False, 'True for debug output'), - 'root': ('e', 'Root symbol for basis vectors'), - 'name': (None, 'Name of submanifold'), - 'norm': (False, 'Normalize basis if True'), - 'ga': (None, 'Base Geometric Algebra')} - - def __init__(self, *args, **kwargs): + # __u is to emulate a Python 3.8 positional-only argument, with a clearer + # spelling than `*args`. + def __init__(self, __u, __coords, *, ga, norm=False, name=None, root='e', debug=False): + """ + Parameters + ---------- + u : + The coordinate map defining the submanifold + which is a list of functions of coordinates of the base + manifold in terms of the coordinates of the submanifold. + for example if the manifold is a unit sphere then - + ``u = [sin(u)*cos(v),sin(u)*sin(v),cos(u)]``. + + Alternatively, a parametric vector function + of the basis vectors of the base manifold. The + coefficients of the bases are functions of the coordinates + (``coords``). In this case we would call the submanifold + a "vector" manifold and additional characteristics of the + manifold can be calculated since we have given an explicit + embedding of the manifold in the base manifold. + coords : + The coordinate list for the submanifold, for + example ``[u, v]``. + debug : + True for debug output + root : str + Root symbol for basis vectors + name : str + Name of submanifold + norm : bool + Normalize basis if True + ga : + Base Geometric Algebra + """ #print '!!!Enter Sm!!!' @@ -1951,10 +1959,8 @@ def __init__(self, *args, **kwargs): printer.GaLatexPrinter.restore() Ga.restore = True - kwargs = metric.test_init_slots(Sm.init_slots, **kwargs) - u = args[0] # Coordinate map or vector embedding to define submanifold - coords = args[1] # List of cordinates - ga = kwargs['ga'] # base geometric algebra + u = __u + coords = __coords if ga is None: raise ValueError('Base geometric algebra must be specified for submanifold.') @@ -1963,7 +1969,6 @@ def __init__(self, *args, **kwargs): n_sub = len(coords) # Construct names of basis vectors - root = kwargs['root'] """ basis_str = '' for x in coords: @@ -2016,9 +2021,6 @@ def __init__(self, *args, **kwargs): s += dxdu[k][i] * dxdu[l][j] * g_base[k, l].subs(sub_pairs) g[i, j] = trigsimp(s) - norm = kwargs['norm'] - debug = kwargs['debug'] - if Ga.restore: # restore printer to appropriate enhanced mode after sm is instantiated printer.GaLatexPrinter.redirect() diff --git a/galgebra/lt.py b/galgebra/lt.py index 026d7451..a2a88cfe 100644 --- a/galgebra/lt.py +++ b/galgebra/lt.py @@ -16,7 +16,6 @@ from . import printer from . import metric from . import mv -from . import utils def aprint(a): out = '' @@ -149,9 +148,6 @@ class Lt(object): """ mat_fmt = False - init_slots = {'ga': (None, 'Name of metric (geometric algebra)'), - 'f': (False, 'True if Lt if function of coordinates.'), - 'mode': ('g', 'g:general, s:symmetric, a:antisymmetric transformation.')} @staticmethod def setup(ga): @@ -165,13 +161,20 @@ def format(mat_fmt=False): Lt.mat_fmt = mat_fmt return - def __init__(self, *args, **kwargs): - kwargs = metric.test_init_slots(Lt.init_slots, **kwargs) - + def __init__(self, *args, ga, f=False, mode='g'): + """ + Parameters + ---------- + ga : + Name of metric (geometric algebra) + f : bool + True if Lt if function of coordinates + mode : str + g:general, s:symmetric, a:antisymmetric transformation + """ mat_rep = args[0] - ga = kwargs['ga'] - self.fct_flg = kwargs['f'] - self.mode = kwargs['mode'] # General g, s, or a transformation + self.fct_flg = f + self.mode = mode self.Ga = ga self.coords = ga.lt_coords self.X = ga.lt_x @@ -221,7 +224,7 @@ def __init__(self, *args, **kwargs): else: raise ValueError('In Spinor input for Lt, S*S.rev() not a scalar!\n') - elif utils.isstr(mat_rep): # String input + elif isinstance(mat_rep, str): # String input Amat = Symbolic_Matrix(mat_rep, coords=self.Ga.coords,mode=self.mode,f=self.fct_flg) self.__init__(Amat, ga=self.Ga) @@ -726,7 +729,7 @@ def __init__(self, f, Ga, args, fct=False): Ga.make_grad(self.args) self.fvalue = (self.args[0] | f(self.args[1])).obj self.f = None - elif utils.isstr(f) and args is not None: + elif isinstance(f, str) and args is not None: self.f = None if isinstance(args,(list,tuple)): self.args = args diff --git a/galgebra/metric.py b/galgebra/metric.py index 344cc856..ad5667ed 100644 --- a/galgebra/metric.py +++ b/galgebra/metric.py @@ -10,7 +10,6 @@ ) from . import printer -from . import utils half = Rational(1, 2) @@ -269,16 +268,6 @@ class Metric(object): count = 1 - init_slots = {'g': (None, 'metric tensor'), - 'coords': (None, 'manifold/vector space coordinate list/tuple'), - 'X': (None, 'vector manifold function'), - 'norm': (False, 'True to normalize basis vectors'), - 'debug': (False, 'True to print out debugging information'), - 'gsym': (None, 'String s to use "det("+s+")" function in reciprocal basis'), - 'sig': ('e', 'Signature of metric, default is (n,0) a Euclidean metric'), - 'Isq': ('-', "Sign of square of pseudo-scalar, default is '-'"), - 'wedge': (True, 'Use ^ symbol to print basis blades')} - @staticmethod def dot_orthogonal(V1, V2, g=None): """ @@ -337,7 +326,7 @@ def metric_symbols_list(self, s=None): # input metric tensor as string s = self.n * (s[:-1] + ',') s = s[:-1] - if utils.isstr(s): + if isinstance(s, str): rows = s.split(',') n_rows = len(rows) @@ -562,7 +551,7 @@ def signature(self): return else: raise ValueError('self.sig = ' + str(self.sig) + ' > self.n, not an allowed hint') - if utils.isstr(self.sig): + if isinstance(self.sig, str): if self.sig == 'e': # Euclidean metric signature self.sig = (self.n, 0) elif self.sig == 'm+': # Minkowski metric signature (n-1,1) @@ -575,24 +564,48 @@ def signature(self): raise ValueError(str(self.sig) + ' is not allowed value for self.sig') - def __init__(self, basis, **kwargs): - - kwargs = test_init_slots(Metric.init_slots, **kwargs) + def __init__(self, basis, *, + g=None, + coords=None, + X=None, + norm=False, + debug=False, + gsym=None, + sig='e', + Isq='-' + ): + """ + Parameters + ---------- + basis : + string specification + g : + metric tensor + coords : + manifold/vector space coordinate list/tuple (sympy symbols) + X : + vector manifold function + norm : + True to normalize basis vectors + debug : + True to print out debugging information + gsym : + String s to use ``"det("+s+")"`` function in reciprocal basis + sig : + Signature of metric, default is (n,0) a Euclidean metric + Isq : + Sign of square of pseudo-scalar, default is '-' + """ self.name = 'GA' + str(Metric.count) Metric.count += 1 - if not utils.isstr(basis): + if not isinstance(basis, str): raise TypeError('"' + str(basis) + '" must be string') - X = kwargs['X'] # Vector manifold - g = kwargs['g'] # Explicit metric or base metric for vector manifold - debug = kwargs['debug'] - coords = kwargs['coords'] # Manifold coordinates (sympy symbols) - norm = kwargs['norm'] # Normalize basis vectors - self.sig = kwargs['sig'] # Hint for metric signature - self.gsym = kwargs['gsym'] - self.Isq = kwargs['Isq'] #: Sign of I**2, only needed if I**2 not a number + self.sig = sig # Hint for metric signature + self.gsym = gsym + self.Isq = Isq #: Sign of I**2, only needed if I**2 not a number self.debug = debug self.is_ortho = False # Is basis othogonal @@ -651,7 +664,7 @@ def __init__(self, basis, **kwargs): printer.oprint('X_{i}', X, 'D_{i}X_{j}', dX) else: # metric is symbolic or list of lists of functions of coordinates - if utils.isstr(g): # metric elements are symbols or constants + if isinstance(g, str): # metric elements are symbols or constants if g == 'g': # general symbolic metric tensor (g_ij functions of position) g_lst = [] g_inv_lst = [] diff --git a/galgebra/mv.py b/galgebra/mv.py index 6fe3a162..2363ed6d 100644 --- a/galgebra/mv.py +++ b/galgebra/mv.py @@ -6,7 +6,6 @@ import numbers import operator from functools import reduce -import sys import warnings from sympy import ( @@ -19,7 +18,6 @@ from . import printer from . import metric -from . import utils from .printer import ZERO_STR from .utils import _KwargParser @@ -178,7 +176,7 @@ def add_superscript(root, s): return '{}__{}'.format(root, s) grade = __grade kw = _KwargParser('_make_grade', kwargs) - if utils.isstr(__name_or_coeffs): + if isinstance(__name_or_coeffs, str): name = __name_or_coeffs f = kw.pop('f', False) kw.reject_remaining() @@ -206,7 +204,7 @@ def add_superscript(root, s): @staticmethod def _make_scalar(ga, __name_or_value, **kwargs): """ Make a scalar multivector """ - if utils.isstr(__name_or_value): + if isinstance(__name_or_value, str): name = __name_or_value return Mv._make_grade(ga, name, 0, **kwargs) else: @@ -262,7 +260,7 @@ def _make_odd(ga, __name, **kwargs): _make_grade2 = _make_bivector _make_even = _make_spinor - def __init__(self, *args, **kwargs): + def __init__(self, *args, ga, recp=None, coords=None, **kwargs): """ __init__(self, *args, ga, recp=None, **kwargs) @@ -328,9 +326,8 @@ def __init__(self, *args, **kwargs): used with multivector functions. """ kw = _KwargParser('__init__', kwargs) - self.Ga = kw.pop('ga') - self.recp = kw.pop('recp', None) # not used - kw.pop('coords', None) # ignored + self.Ga = ga + self.recp = recp # not used self.char_Mv = False self.i_grade = None # if pure grade mv, grade value @@ -345,7 +342,7 @@ def __init__(self, *args, **kwargs): self.obj = S(0) self.i_grade = 0 kw.reject_remaining() - elif len(args) == 1 and not utils.isstr(args[0]): # copy constructor + elif len(args) == 1 and not isinstance(args[0], str): # copy constructor x = args[0] if isinstance(x, Mv): self.obj = x.obj @@ -360,7 +357,7 @@ def __init__(self, *args, **kwargs): self.characterise_Mv() kw.reject_remaining() else: - if utils.isstr(args[1]): + if isinstance(args[1], str): make_args = list(args) mode = make_args.pop(1) make_func = getattr(Mv, '_make_{}'.format(mode), None) @@ -378,7 +375,7 @@ def __init__(self, *args, **kwargs): else: raise TypeError("Expected string or int") - if utils.isstr(args[0]): + if isinstance(args[0], str): self.title = args[0] self.characterise_Mv() @@ -457,10 +454,6 @@ def __eq__(self, A): else: return False - if sys.version_info.major < 3: - def __ne__(self, other): - return not (self == other) - """ def __eq__(self, A): if not isinstance(A, Mv): @@ -584,9 +577,6 @@ def __truediv__(self, A): else: return self * (S(1)/A) - if sys.version_info.major < 3: - __div__ = __truediv__ - def __str__(self): if printer.GaLatexPrinter.latex_flg: Printer = printer.GaLatexPrinter @@ -676,13 +666,12 @@ def Mv_latex_str(self): if self.obj == 0: return ZERO_STR - # todo: use the nonlocal keyword here instead once we drop python 2 - class first_line: - value = True + first_line = True def append_plus(c_str): - if first_line.value: - first_line.value = False + nonlocal first_line + if first_line: + first_line = False return c_str else: c_str = c_str.strip() @@ -759,7 +748,7 @@ def append_plus(c_str): elif printer.GaLatexPrinter.fmt == 2: # One grade per line if grade != old_grade: old_grade = grade - if not first_line.value: + if not first_line: lines.append(s) s = append_plus(cb_str) else: @@ -1561,10 +1550,8 @@ def __str__(self): def __repr__(self): return str(self) - def __init__(self, *args, **kwargs): - kwargs = metric.test_init_slots(Sdop.init_slots, **kwargs) - - self.Ga = kwargs['ga'] # Associated geometric algebra (coords) + def __init__(self, *args, ga): + self.Ga = ga # Associated geometric algebra (coords) if self.Ga is None: raise ValueError('In Sdop.__init__ self.Ga must be defined.') @@ -1626,10 +1613,6 @@ def __eq__(self, other): else: return NotImplemented - if sys.version_info.major < 3: - def __ne__(self, other): - return not (self == other) - def __add__(self, sdop): return Sdop.Add(self, sdop) @@ -1699,11 +1682,7 @@ def __eq__(self,A): return True return False - if sys.version_info.major < 3: - def __ne__(self, other): - return not (self == other) - - def __init__(self, __arg, **kwargs): + def __init__(self, __arg, *, ga): """ The partial differential operator is a partial derivative with respect to a set of real symbols (variables). The allowed @@ -1714,9 +1693,7 @@ def __init__(self, __arg, **kwargs): """ - kwargs = metric.test_init_slots(Pdop.init_slots, **kwargs) - - self.Ga = kwargs['ga'] # Associated geometric algebra + self.Ga = ga # Associated geometric algebra if self.Ga is None: raise ValueError('In Pdop.__init__ self.Ga must be defined.') @@ -1917,22 +1894,27 @@ class Dop(object): terms : list of tuples """ - init_slots = {'ga': (None, 'Associated geometric algebra'), - 'cmpflg': (False, 'Complement flag for Dop'), - 'debug': (False, 'True to print out debugging information'), - 'fmt_dop': (1, '1 for normal dop partial derivative formating')} - - def __init__(self, *args, **kwargs): - - kwargs = metric.test_init_slots(Dop.init_slots, **kwargs) + def __init__(self, *args, ga, cmpflg=False, debug=False, fmt_dop=1): + """ + Parameters + ---------- + ga : + Associated geometric algebra + cmpflg : bool + Complement flag for Dop + debug : bool + True to print out debugging information + fmt_dop : + 1 for normal dop partial derivative formatting + """ - self.cmpflg = kwargs['cmpflg'] # Complement flag (default False) - self.Ga = kwargs['ga'] + self.cmpflg = cmpflg + self.Ga = ga if self.Ga is None: raise ValueError('In Dop.__init__ self.Ga must be defined.') - self.dop_fmt = kwargs['fmt_dop'] # Partial derivative output format (default 1) + self.dop_fmt = fmt_dop self.title = None if len(args) == 2: @@ -2081,9 +2063,6 @@ def __truediv__(self, dopr): (coef / dopr, pdiff) for (coef, pdiff) in self.terms ], ga=self.Ga, cmpflg=self.cmpflg) - if sys.version_info.major < 3: - __div__ = __truediv__ - def __mul__(self, dopr): # * geometric product return Dop.Mul(self, dopr, op='*') @@ -2118,10 +2097,6 @@ def __eq__(self, other): else: return NotImplemented - if sys.version_info.major < 3: - def __ne__(self, other): - return not (self == other) - def __str__(self): if printer.GaLatexPrinter.latex_flg: Printer = printer.GaLatexPrinter diff --git a/galgebra/printer.py b/galgebra/printer.py index 89767901..4bd9c765 100644 --- a/galgebra/printer.py +++ b/galgebra/printer.py @@ -13,7 +13,6 @@ from sympy.core.function import _coeff_isneg from sympy.core.operations import AssocOp from sympy import init_printing -from . import utils try: from IPython.display import display, Latex, Math, display_latex @@ -199,7 +198,7 @@ def coef_simplify(expr): return expr -def oprint(*args, **kwargs): +def oprint(*args, dict_mode=False): """ Debug printing for iterated (list/tuple/dict/set) objects. args is of form (title1,object1,title2,object2,...) and prints: @@ -211,12 +210,7 @@ def oprint(*args, **kwargs): If you only wish to print a title set object = None. """ - if 'dict_mode' in kwargs: - dict_mode = kwargs['dict_mode'] - else: - dict_mode = False - - if utils.isstr(args[0]) or args[0] is None: + if isinstance(args[0], str) or args[0] is None: titles = list(islice(args, None, None, 2)) objs = tuple(islice(args, 1, None, 2)) if len(args) > 2: @@ -631,7 +625,7 @@ def redirect(): pass else: GaLatexPrinter.stdout = sys.stdout - sys.stdout = utils.StringIO() + sys.stdout = io.StringIO() return @staticmethod diff --git a/galgebra/utils.py b/galgebra/utils.py index e7e7cfa8..532afee5 100644 --- a/galgebra/utils.py +++ b/galgebra/utils.py @@ -9,12 +9,8 @@ PY2 = sys.version_info[0] == 2 PY3 = sys.version_info[0] == 3 -if PY3: - string_types = str - from io import StringIO -else: - string_types = basestring - from StringIO import StringIO +string_types = str +from io import StringIO # https://stackoverflow.com/questions/16176742/python-3-replacement-for-deprecated-compiler-ast-flatten-function @@ -31,7 +27,7 @@ def flatten(x): def isstr(s): - return isinstance(s, string_types) + return isinstance(s, str) class _KwargParser: diff --git a/setup.py b/setup.py index 7f1511cb..87314cac 100644 --- a/setup.py +++ b/setup.py @@ -20,8 +20,7 @@ packages=find_packages(), package_dir={'galgebra':'galgebra'}, install_requires = ['sympy'], - # 2.7 or >=3.5 - python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', + python_requires='>=3.5.*', long_description=LONG_DESCRIPTION, classifiers=[ 'Development Status :: 4 - Beta', @@ -30,7 +29,6 @@ 'License :: OSI Approved :: BSD License', 'Natural Language :: English', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/test/test_mv.py b/test/test_mv.py index 22b4e25a..c107b8fe 100644 --- a/test/test_mv.py +++ b/test/test_mv.py @@ -3,7 +3,6 @@ import pytest from sympy import Symbol from galgebra.ga import Ga -from galgebra import utils class TestMv(unittest.TestCase): diff --git a/test/test_test.py b/test/test_test.py index 546cef03..50e96c46 100644 --- a/test/test_test.py +++ b/test/test_test.py @@ -7,7 +7,6 @@ # for backward compatibility from galgebra.mv import ONE, ZERO, HALF from galgebra import ga -from galgebra import utils def F(x): global n, nbar @@ -15,7 +14,7 @@ def F(x): return(Fx) def make_vector(a, n=3, ga=None): - if utils.isstr(a): + if isinstance(a, str): v = zero for i in range(n): a_i = Symbol(a+str(i+1))