Skip to content

Commit dba6527

Browse files
authored
Merge pull request #424 from cclauss/pyupgrade_py37-plus
pyupgrade --py37-plus **/*.py
2 parents 29b82e2 + 0d01148 commit dba6527

19 files changed

+31
-42
lines changed

benchmarks/expand2_sage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
from timeit import default_timer as clock
32
from sage.all import var
43
var("x y z w")

benchmarks/expand3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import sys
32
sys.path.append("..")
43
from timeit import default_timer as clock

benchmarks/expand3_sage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
from timeit import default_timer as clock
32
from sage.all import var
43
var("x y z")

benchmarks/expand4_sage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
print("import...")
32
from timeit import default_timer as clock
43
from sage.all import var

benchmarks/expand5.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import sys
32
sys.path.append("..")
43
from timeit import default_timer as clock

benchmarks/expand5_sage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
from timeit import default_timer as clock
32
from sage.all import var
43
var("x y z")

benchmarks/heterogeneous_output_Lambdify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import warnings
1010

1111
src = os.path.join(os.path.dirname(__file__), '6_links_rhs.txt')
12-
serial = open(src, 'tr').read()
12+
serial = open(src).read()
1313
parsed = parse_expr(serial, transformations=standard_transformations)
1414
vec = sp.Matrix(1, 14, parsed)
1515
args = tuple(sorted(vec.free_symbols, key=lambda arg: arg.name))

benchmarks/kane.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import sys
32
sys.path.append("..")
43
from timeit import default_timer as clock

benchmarks/kane_generate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ def test_bicycle():
188188
PaperForkCgZ = 0.7
189189
FrameLength = evalf.N(PaperWb*sin(HTA)-(rake-(PaperRadFront-PaperRadRear)*cos(HTA)))
190190
FrameCGNorm = evalf.N((PaperFrameCgZ - PaperRadRear-(PaperFrameCgX/sin(HTA))*cos(HTA))*sin(HTA))
191-
FrameCGPar = evalf.N((PaperFrameCgX / sin(HTA) + (PaperFrameCgZ - PaperRadRear - PaperFrameCgX / sin(HTA) * cos(HTA)) * cos(HTA)))
192-
tempa = evalf.N((PaperForkCgZ - PaperRadFront))
193-
tempb = evalf.N((PaperWb-PaperForkCgX))
191+
FrameCGPar = evalf.N(PaperFrameCgX / sin(HTA) + (PaperFrameCgZ - PaperRadRear - PaperFrameCgX / sin(HTA) * cos(HTA)) * cos(HTA))
192+
tempa = evalf.N(PaperForkCgZ - PaperRadFront)
193+
tempb = evalf.N(PaperWb-PaperForkCgX)
194194
tempc = evalf.N(sqrt(tempa**2+tempb**2))
195-
PaperForkL = evalf.N((PaperWb*cos(HTA)-(PaperRadFront-PaperRadRear)*sin(HTA)))
195+
PaperForkL = evalf.N(PaperWb*cos(HTA)-(PaperRadFront-PaperRadRear)*sin(HTA))
196196
ForkCGNorm = evalf.N(rake+(tempc * sin(pi/2-HTA-acos(tempa/tempc))))
197197
ForkCGPar = evalf.N(tempc * cos((pi/2-HTA)-acos(tempa/tempc))-PaperForkL)
198198

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ def cmake_build(self):
119119
if not path.exists(path.join(build_dir, "CMakeCache.txt")):
120120
cmake_cmd.extend(self.get_generator())
121121
if subprocess.call(cmake_cmd, cwd=build_dir) != 0:
122-
raise EnvironmentError("error calling cmake")
122+
raise OSError("error calling cmake")
123123

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

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

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

187187
import compileall
188188
compileall.compile_dir(path.join(self.install_platlib, "symengine"))

symengine/printing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CCodePrinter:
44

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

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

1616
assign_to = str(assign_to)
1717
if not expr.is_Matrix:
18-
return "{} = {};".format(assign_to, ccode(expr))
18+
return f"{assign_to} = {ccode(expr)};"
1919

2020
code_lines = []
2121
for i, element in enumerate(expr):
22-
code_line = '{}[{}] = {};'.format(assign_to, i, element)
22+
code_line = f'{assign_to}[{i}] = {element};'
2323
code_lines.append(code_line)
2424
return '\n'.join(code_lines)
2525

symengine/test_utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def raises(expectedException, code=None):
8080
raise TypeError(
8181
'raises() expects a callable for the 2nd argument.')
8282

83-
class RaisesContext(object):
83+
class RaisesContext:
8484
def __init__(self, expectedException):
8585
self.expectedException = expectedException
8686

symengine/tests/test_arit.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,27 @@ def test_args():
133133
y = Symbol("y")
134134
assert (x**2).args == (x, 2)
135135
assert (x**2 + 5).args == (5, x**2)
136-
assert set((x**2 + 2*x*y + 5).args) == set((x**2, 2*x*y, Integer(5)))
136+
assert set((x**2 + 2*x*y + 5).args) == {x**2, 2*x*y, Integer(5)}
137137
assert (2*x**2).args == (2, x**2)
138-
assert set((2*x**2*y).args) == set((Integer(2), x**2, y))
138+
assert set((2*x**2*y).args) == {Integer(2), x**2, y}
139139

140140

141141
def test_atoms():
142142
x = Symbol("x")
143143
y = Symbol("y")
144144
z = Symbol("z")
145-
assert (x**2).atoms() == set([x])
146-
assert (x**2).atoms(Symbol) == set([x])
147-
assert (x ** y + z).atoms() == set([x, y, z])
148-
assert (x**y + z).atoms(Symbol) == set([x, y, z])
145+
assert (x**2).atoms() == {x}
146+
assert (x**2).atoms(Symbol) == {x}
147+
assert (x ** y + z).atoms() == {x, y, z}
148+
assert (x**y + z).atoms(Symbol) == {x, y, z}
149149

150150

151151
def test_free_symbols():
152152
x = Symbol("x")
153153
y = Symbol("y")
154154
z = Symbol("z")
155-
assert (x**2).free_symbols == set([x])
156-
assert (x**y + z).free_symbols == set([x, y, z])
155+
assert (x**2).free_symbols == {x}
156+
assert (x**y + z).free_symbols == {x, y, z}
157157

158158

159159
def test_as_numer_denom():

symengine/tests/test_dict_basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def test_DictBasic():
1818
assert d[2*z] == x
1919
if 2*z not in d:
2020
assert False
21-
assert set(d.items()) == set([(2*z, x), (x, Integer(2)), (y, z)])
21+
assert set(d.items()) == {(2*z, x), (x, Integer(2)), (y, z)}
2222

2323
del d[x]
24-
assert set(d.keys()) == set([2*z, y])
25-
assert set(d.values()) == set([x, z])
24+
assert set(d.keys()) == {2*z, y}
25+
assert set(d.values()) == {x, z}
2626

2727
e = y + sin(2*z)
2828
assert e.subs(d) == z + sin(x)

symengine/tests/test_lambdify.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import (absolute_import, division, print_function)
3-
4-
51
import array
62
import cmath
73
from functools import reduce

symengine/tests/test_matrices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def test_atoms():
721721
a = Symbol("a")
722722
b = Symbol("b")
723723
X = DenseMatrix([[a, 2], [b, 4]])
724-
assert X.atoms(Symbol) == set([a, b])
724+
assert X.atoms(Symbol) == {a, b}
725725

726726

727727
def test_LUdecomp():

symengine/tests/test_symbol.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_symbols():
4848

4949
assert symbols(('x', 'y', 'z')) == (x, y, z)
5050
assert symbols(['x', 'y', 'z']) == [x, y, z]
51-
assert symbols(set(['x', 'y', 'z'])) == set([x, y, z])
51+
assert symbols({'x', 'y', 'z'}) == {x, y, z}
5252

5353
raises(ValueError, lambda: symbols(''))
5454
raises(ValueError, lambda: symbols(','))
@@ -104,13 +104,13 @@ def sym(s):
104104
assert sym('a0:4') == '(a0, a1, a2, a3)'
105105
assert sym('a2:4,b1:3') == '(a2, a3, b1, b2)'
106106
assert sym('a1(2:4)') == '(a12, a13)'
107-
assert sym(('a0:2.0:2')) == '(a0.0, a0.1, a1.0, a1.1)'
108-
assert sym(('aa:cz')) == '(aaz, abz, acz)'
107+
assert sym('a0:2.0:2') == '(a0.0, a0.1, a1.0, a1.1)'
108+
assert sym('aa:cz') == '(aaz, abz, acz)'
109109
assert sym('aa:c0:2') == '(aa0, aa1, ab0, ab1, ac0, ac1)'
110110
assert sym('aa:ba:b') == '(aaa, aab, aba, abb)'
111111
assert sym('a:3b') == '(a0b, a1b, a2b)'
112112
assert sym('a-1:3b') == '(a-1b, a-2b)'
113-
assert sym('a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
113+
assert sym(r'a:2\,:2' + chr(0)) == '(a0,0%s, a0,1%s, a1,0%s, a1,1%s)' % (
114114
(chr(0),)*4)
115115
assert sym('x(:a:3)') == '(x(a0), x(a1), x(a2))'
116116
assert sym('x(:c):1') == '(xa0, xb0, xc0)'

symengine/tests/test_sympify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_S():
4444

4545

4646
def test_sympify_error1a():
47-
class Test(object):
47+
class Test:
4848
pass
4949
raises(SympifyError, lambda: sympify(Test()))
5050

symengine/tests/test_sympy_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def __new__(cls, name, extra_attribute):
183183
return Symbol.__new__(cls, name)
184184

185185
def __init__(self, name, extra_attribute):
186-
super(Wrapper, self).__init__(name)
186+
super().__init__(name)
187187
self.extra_attribute = extra_attribute
188188

189189
# Instantiate the subclass

0 commit comments

Comments
 (0)