Skip to content

Commit

Permalink
Merge pull request #424 from cclauss/pyupgrade_py37-plus
Browse files Browse the repository at this point in the history
pyupgrade --py37-plus **/*.py
  • Loading branch information
isuruf authored Oct 10, 2022
2 parents 29b82e2 + 0d01148 commit dba6527
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 42 deletions.
1 change: 0 additions & 1 deletion benchmarks/expand2_sage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from timeit import default_timer as clock
from sage.all import var
var("x y z w")
Expand Down
1 change: 0 additions & 1 deletion benchmarks/expand3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import sys
sys.path.append("..")
from timeit import default_timer as clock
Expand Down
1 change: 0 additions & 1 deletion benchmarks/expand3_sage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from timeit import default_timer as clock
from sage.all import var
var("x y z")
Expand Down
1 change: 0 additions & 1 deletion benchmarks/expand4_sage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
print("import...")
from timeit import default_timer as clock
from sage.all import var
Expand Down
1 change: 0 additions & 1 deletion benchmarks/expand5.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import sys
sys.path.append("..")
from timeit import default_timer as clock
Expand Down
1 change: 0 additions & 1 deletion benchmarks/expand5_sage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
from timeit import default_timer as clock
from sage.all import var
var("x y z")
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/heterogeneous_output_Lambdify.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import warnings

src = os.path.join(os.path.dirname(__file__), '6_links_rhs.txt')
serial = open(src, 'tr').read()
serial = open(src).read()
parsed = parse_expr(serial, transformations=standard_transformations)
vec = sp.Matrix(1, 14, parsed)
args = tuple(sorted(vec.free_symbols, key=lambda arg: arg.name))
Expand Down
1 change: 0 additions & 1 deletion benchmarks/kane.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import sys
sys.path.append("..")
from timeit import default_timer as clock
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/kane_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ def test_bicycle():
PaperForkCgZ = 0.7
FrameLength = evalf.N(PaperWb*sin(HTA)-(rake-(PaperRadFront-PaperRadRear)*cos(HTA)))
FrameCGNorm = evalf.N((PaperFrameCgZ - PaperRadRear-(PaperFrameCgX/sin(HTA))*cos(HTA))*sin(HTA))
FrameCGPar = evalf.N((PaperFrameCgX / sin(HTA) + (PaperFrameCgZ - PaperRadRear - PaperFrameCgX / sin(HTA) * cos(HTA)) * cos(HTA)))
tempa = evalf.N((PaperForkCgZ - PaperRadFront))
tempb = evalf.N((PaperWb-PaperForkCgX))
FrameCGPar = evalf.N(PaperFrameCgX / sin(HTA) + (PaperFrameCgZ - PaperRadRear - PaperFrameCgX / sin(HTA) * cos(HTA)) * cos(HTA))
tempa = evalf.N(PaperForkCgZ - PaperRadFront)
tempb = evalf.N(PaperWb-PaperForkCgX)
tempc = evalf.N(sqrt(tempa**2+tempb**2))
PaperForkL = evalf.N((PaperWb*cos(HTA)-(PaperRadFront-PaperRadRear)*sin(HTA)))
PaperForkL = evalf.N(PaperWb*cos(HTA)-(PaperRadFront-PaperRadRear)*sin(HTA))
ForkCGNorm = evalf.N(rake+(tempc * sin(pi/2-HTA-acos(tempa/tempc))))
ForkCGPar = evalf.N(tempc * cos((pi/2-HTA)-acos(tempa/tempc))-PaperForkL)

Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ def cmake_build(self):
if not path.exists(path.join(build_dir, "CMakeCache.txt")):
cmake_cmd.extend(self.get_generator())
if subprocess.call(cmake_cmd, cwd=build_dir) != 0:
raise EnvironmentError("error calling cmake")
raise OSError("error calling cmake")

if subprocess.call(["cmake", "--build", ".",
"--config", cmake_build_type[0]],
cwd=build_dir) != 0:
raise EnvironmentError("error building project")
raise OSError("error building project")

def get_generator(self):
if cmake_generator[0]:
Expand Down Expand Up @@ -176,13 +176,13 @@ def cmake_install(self):
# CMake has to be called here to update PYTHON_INSTALL_PATH
# if build and install were called separately by the user
if subprocess.call(cmake_cmd, cwd=build_dir) != 0:
raise EnvironmentError("error calling cmake")
raise OSError("error calling cmake")

if subprocess.call(["cmake", "--build", ".",
"--config", cmake_build_type[0],
"--target", "install"],
cwd=build_dir) != 0:
raise EnvironmentError("error installing")
raise OSError("error installing")

import compileall
compileall.compile_dir(path.join(self.install_platlib, "symengine"))
Expand Down
6 changes: 3 additions & 3 deletions symengine/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CCodePrinter:

def doprint(self, expr, assign_to=None):
if not isinstance(assign_to, (Basic, type(None), str)):
raise TypeError("{0} cannot assign to object of type {1}".format(
raise TypeError("{} cannot assign to object of type {}".format(
type(self).__name__, type(assign_to)))

expr = sympify(expr)
Expand All @@ -15,11 +15,11 @@ def doprint(self, expr, assign_to=None):

assign_to = str(assign_to)
if not expr.is_Matrix:
return "{} = {};".format(assign_to, ccode(expr))
return f"{assign_to} = {ccode(expr)};"

code_lines = []
for i, element in enumerate(expr):
code_line = '{}[{}] = {};'.format(assign_to, i, element)
code_line = f'{assign_to}[{i}] = {element};'
code_lines.append(code_line)
return '\n'.join(code_lines)

Expand Down
2 changes: 1 addition & 1 deletion symengine/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def raises(expectedException, code=None):
raise TypeError(
'raises() expects a callable for the 2nd argument.')

class RaisesContext(object):
class RaisesContext:
def __init__(self, expectedException):
self.expectedException = expectedException

Expand Down
16 changes: 8 additions & 8 deletions symengine/tests/test_arit.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,27 @@ def test_args():
y = Symbol("y")
assert (x**2).args == (x, 2)
assert (x**2 + 5).args == (5, x**2)
assert set((x**2 + 2*x*y + 5).args) == set((x**2, 2*x*y, Integer(5)))
assert set((x**2 + 2*x*y + 5).args) == {x**2, 2*x*y, Integer(5)}
assert (2*x**2).args == (2, x**2)
assert set((2*x**2*y).args) == set((Integer(2), x**2, y))
assert set((2*x**2*y).args) == {Integer(2), x**2, y}


def test_atoms():
x = Symbol("x")
y = Symbol("y")
z = Symbol("z")
assert (x**2).atoms() == set([x])
assert (x**2).atoms(Symbol) == set([x])
assert (x ** y + z).atoms() == set([x, y, z])
assert (x**y + z).atoms(Symbol) == set([x, y, z])
assert (x**2).atoms() == {x}
assert (x**2).atoms(Symbol) == {x}
assert (x ** y + z).atoms() == {x, y, z}
assert (x**y + z).atoms(Symbol) == {x, y, z}


def test_free_symbols():
x = Symbol("x")
y = Symbol("y")
z = Symbol("z")
assert (x**2).free_symbols == set([x])
assert (x**y + z).free_symbols == set([x, y, z])
assert (x**2).free_symbols == {x}
assert (x**y + z).free_symbols == {x, y, z}


def test_as_numer_denom():
Expand Down
6 changes: 3 additions & 3 deletions symengine/tests/test_dict_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def test_DictBasic():
assert d[2*z] == x
if 2*z not in d:
assert False
assert set(d.items()) == set([(2*z, x), (x, Integer(2)), (y, z)])
assert set(d.items()) == {(2*z, x), (x, Integer(2)), (y, z)}

del d[x]
assert set(d.keys()) == set([2*z, y])
assert set(d.values()) == set([x, z])
assert set(d.keys()) == {2*z, y}
assert set(d.values()) == {x, z}

e = y + sin(2*z)
assert e.subs(d) == z + sin(x)
4 changes: 0 additions & 4 deletions symengine/tests/test_lambdify.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)


import array
import cmath
from functools import reduce
Expand Down
2 changes: 1 addition & 1 deletion symengine/tests/test_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def test_atoms():
a = Symbol("a")
b = Symbol("b")
X = DenseMatrix([[a, 2], [b, 4]])
assert X.atoms(Symbol) == set([a, b])
assert X.atoms(Symbol) == {a, b}


def test_LUdecomp():
Expand Down
8 changes: 4 additions & 4 deletions symengine/tests/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_symbols():

assert symbols(('x', 'y', 'z')) == (x, y, z)
assert symbols(['x', 'y', 'z']) == [x, y, z]
assert symbols(set(['x', 'y', 'z'])) == set([x, y, z])
assert symbols({'x', 'y', 'z'}) == {x, y, z}

raises(ValueError, lambda: symbols(''))
raises(ValueError, lambda: symbols(','))
Expand Down Expand Up @@ -104,13 +104,13 @@ def sym(s):
assert sym('a0:4') == '(a0, a1, a2, a3)'
assert sym('a2:4,b1:3') == '(a2, a3, b1, b2)'
assert sym('a1(2:4)') == '(a12, a13)'
assert sym(('a0:2.0:2')) == '(a0.0, a0.1, a1.0, a1.1)'
assert sym(('aa:cz')) == '(aaz, abz, acz)'
assert sym('a0:2.0:2') == '(a0.0, a0.1, a1.0, a1.1)'
assert sym('aa:cz') == '(aaz, abz, acz)'
assert sym('aa:c0:2') == '(aa0, aa1, ab0, ab1, ac0, ac1)'
assert sym('aa:ba:b') == '(aaa, aab, aba, abb)'
assert sym('a:3b') == '(a0b, a1b, a2b)'
assert sym('a-1:3b') == '(a-1b, a-2b)'
assert sym('a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
assert sym(r'a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
(chr(0),)*4)
assert sym('x(:a:3)') == '(x(a0), x(a1), x(a2))'
assert sym('x(:c):1') == '(xa0, xb0, xc0)'
Expand Down
2 changes: 1 addition & 1 deletion symengine/tests/test_sympify.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_S():


def test_sympify_error1a():
class Test(object):
class Test:
pass
raises(SympifyError, lambda: sympify(Test()))

Expand Down
2 changes: 1 addition & 1 deletion symengine/tests/test_sympy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def __new__(cls, name, extra_attribute):
return Symbol.__new__(cls, name)

def __init__(self, name, extra_attribute):
super(Wrapper, self).__init__(name)
super().__init__(name)
self.extra_attribute = extra_attribute

# Instantiate the subclass
Expand Down

0 comments on commit dba6527

Please sign in to comment.