Skip to content

Commit

Permalink
all: Update Python formatting to latest Black version 22.1.0.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Feb 2, 2022
1 parent 326b2c7 commit ab2923d
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 83 deletions.
2 changes: 1 addition & 1 deletion examples/rp2/pio_pwm.py
Expand Up @@ -41,5 +41,5 @@ def set(self, value):

while True:
for i in range(256):
pwm.set(i ** 2)
pwm.set(i**2)
sleep(0.01)
2 changes: 1 addition & 1 deletion tests/cpydiff/modules_random_randint.py
Expand Up @@ -8,5 +8,5 @@
import random


x = random.randint(2 ** 128 - 1, 2 ** 128)
x = random.randint(2**128 - 1, 2**128)
print("x={}".format(x))
14 changes: 7 additions & 7 deletions tests/float/complex1.py
Expand Up @@ -27,15 +27,15 @@
print(1j / 2)
print((1j / 2j).real)
print(1j / (1 + 2j))
ans = 0j ** 0
ans = 0j**0
print("%.5g %.5g" % (ans.real, ans.imag))
ans = 0j ** 1
ans = 0j**1
print("%.5g %.5g" % (ans.real, ans.imag))
ans = 0j ** 0j
ans = 0j**0j
print("%.5g %.5g" % (ans.real, ans.imag))
ans = 1j ** 2.5
ans = 1j**2.5
print("%.5g %.5g" % (ans.real, ans.imag))
ans = 1j ** 2.5j
ans = 1j**2.5j
print("%.5g %.5g" % (ans.real, ans.imag))

# comparison
Expand Down Expand Up @@ -116,10 +116,10 @@

# zero division via power
try:
0j ** -1
0j**-1
except ZeroDivisionError:
print("ZeroDivisionError")
try:
0j ** 1j
0j**1j
except ZeroDivisionError:
print("ZeroDivisionError")
2 changes: 1 addition & 1 deletion tests/float/float1.py
Expand Up @@ -88,7 +88,7 @@
print("ZeroDivisionError")

try:
0.0 ** -1
0.0**-1
except ZeroDivisionError:
print("ZeroDivisionError")

Expand Down
36 changes: 18 additions & 18 deletions tests/float/float2int_doubleprec_intbig.py
Expand Up @@ -35,16 +35,16 @@
print(int(1418774543.0))
print("%d" % 1418774543.0)
if ll_type == 3:
print(int(2.0 ** 100))
print("%d" % 2.0 ** 100)
print(int(2.0**100))
print("%d" % 2.0**100)
else:
print(int(1073741823.0))
print("%d" % 1073741823.0)

testpass = True
p2_rng = ((30, 63, 1024), (62, 63, 1024))[is_64bit][ll_type]
for i in range(0, p2_rng):
bitcnt = len(bin(int(2.0 ** i))) - 3
bitcnt = len(bin(int(2.0**i))) - 3
if i != bitcnt:
print("fail: 2**%u was %u bits long" % (i, bitcnt))
testpass = False
Expand All @@ -53,7 +53,7 @@
testpass = True
p10_rng = ((9, 18, 23), (18, 18, 23))[is_64bit][ll_type]
for i in range(0, p10_rng):
digcnt = len(str(int(10.0 ** i))) - 1
digcnt = len(str(int(10.0**i))) - 1
if i != digcnt:
print("fail: 10**%u was %u digits long" % (i, digcnt))
testpass = False
Expand All @@ -72,28 +72,28 @@ def fp2int_test(num, name, should_fail):
if ll_type != 2:
if ll_type == 0:
if is_64bit:
neg_bad_fp = -1.00000005 * 2.0 ** 62.0
pos_bad_fp = 2.0 ** 62.0
neg_good_fp = -(2.0 ** 62.0)
pos_good_fp = 0.99999993 * 2.0 ** 62.0
neg_bad_fp = -1.00000005 * 2.0**62.0
pos_bad_fp = 2.0**62.0
neg_good_fp = -(2.0**62.0)
pos_good_fp = 0.99999993 * 2.0**62.0
else:
neg_bad_fp = -1.00000005 * 2.0 ** 30.0
pos_bad_fp = 2.0 ** 30.0
neg_good_fp = -(2.0 ** 30.0)
pos_good_fp = 0.9999999499 * 2.0 ** 30.0
neg_bad_fp = -1.00000005 * 2.0**30.0
pos_bad_fp = 2.0**30.0
neg_good_fp = -(2.0**30.0)
pos_good_fp = 0.9999999499 * 2.0**30.0
else:
neg_bad_fp = -0.51 * 2.0 ** 64.0
pos_bad_fp = 2.0 ** 63.0
neg_good_fp = -(2.0 ** 63.0)
pos_good_fp = 1.9999998 * 2.0 ** 62.0
neg_bad_fp = -0.51 * 2.0**64.0
pos_bad_fp = 2.0**63.0
neg_good_fp = -(2.0**63.0)
pos_good_fp = 1.9999998 * 2.0**62.0

fp2int_test(neg_bad_fp, "neg bad", True)
fp2int_test(pos_bad_fp, "pos bad", True)
fp2int_test(neg_good_fp, "neg good", False)
fp2int_test(pos_good_fp, "pos good", False)
else:
fp2int_test(-1.9999999999999981 * 2.0 ** 1023.0, "large neg", False)
fp2int_test(1.9999999999999981 * 2.0 ** 1023.0, "large pos", False)
fp2int_test(-1.9999999999999981 * 2.0**1023.0, "large neg", False)
fp2int_test(1.9999999999999981 * 2.0**1023.0, "large pos", False)

fp2int_test(float("inf"), "inf test", True)
fp2int_test(float("-inf"), "inf test", True)
Expand Down
36 changes: 18 additions & 18 deletions tests/float/float2int_fp30_intbig.py
Expand Up @@ -34,13 +34,13 @@
print(int(14187744.0))
print("%d" % 14187744.0)
if ll_type == 2:
print(int(2.0 ** 100))
print("%d" % 2.0 ** 100)
print(int(2.0**100))
print("%d" % 2.0**100)

testpass = True
p2_rng = ((30, 63, 127), (62, 63, 127))[is_64bit][ll_type]
for i in range(0, p2_rng):
bitcnt = len(bin(int(2.0 ** i))) - 3
bitcnt = len(bin(int(2.0**i))) - 3
if i != bitcnt:
print("fail: 2.**%u was %u bits long" % (i, bitcnt))
testpass = False
Expand All @@ -50,7 +50,7 @@
testpass = True
p10_rng = 9
for i in range(0, p10_rng):
digcnt = len(str(int(10.0 ** i))) - 1
digcnt = len(str(int(10.0**i))) - 1
if i != digcnt:
print("fail: 10.**%u was %u digits long" % (i, digcnt))
testpass = False
Expand All @@ -69,28 +69,28 @@ def fp2int_test(num, name, should_fail):
if ll_type != 2:
if ll_type == 0:
if is_64bit:
neg_bad_fp = -1.00000005 * 2.0 ** 62.0
pos_bad_fp = 2.0 ** 62.0
neg_good_fp = -(2.0 ** 62.0)
pos_good_fp = 0.99999993 * 2.0 ** 62.0
neg_bad_fp = -1.00000005 * 2.0**62.0
pos_bad_fp = 2.0**62.0
neg_good_fp = -(2.0**62.0)
pos_good_fp = 0.99999993 * 2.0**62.0
else:
neg_bad_fp = -1.00000005 * 2.0 ** 30.0
pos_bad_fp = 2.0 ** 30.0
neg_good_fp = -(2.0 ** 30.0)
pos_good_fp = 0.9999999499 * 2.0 ** 30.0
neg_bad_fp = -1.00000005 * 2.0**30.0
pos_bad_fp = 2.0**30.0
neg_good_fp = -(2.0**30.0)
pos_good_fp = 0.9999999499 * 2.0**30.0
else:
neg_bad_fp = -0.51 * 2.0 ** 64.0
pos_bad_fp = 2.0 ** 63.0
neg_good_fp = -(2.0 ** 63.0)
pos_good_fp = 1.9999998 * 2.0 ** 62.0
neg_bad_fp = -0.51 * 2.0**64.0
pos_bad_fp = 2.0**63.0
neg_good_fp = -(2.0**63.0)
pos_good_fp = 1.9999998 * 2.0**62.0

fp2int_test(neg_bad_fp, "neg bad", True)
fp2int_test(pos_bad_fp, "pos bad", True)
fp2int_test(neg_good_fp, "neg good", False)
fp2int_test(pos_good_fp, "pos good", False)
else:
fp2int_test(-1.999999879 * 2.0 ** 126.0, "large neg", False)
fp2int_test(1.999999879 * 2.0 ** 126.0, "large pos", False)
fp2int_test(-1.999999879 * 2.0**126.0, "large neg", False)
fp2int_test(1.999999879 * 2.0**126.0, "large pos", False)

fp2int_test(float("inf"), "inf test", True)
fp2int_test(float("-inf"), "inf test", True)
Expand Down
36 changes: 18 additions & 18 deletions tests/float/float2int_intbig.py
Expand Up @@ -37,13 +37,13 @@
print("%d" % 14187745.)
# fmt: on
if ll_type == 2:
print(int(2.0 ** 100))
print("%d" % 2.0 ** 100)
print(int(2.0**100))
print("%d" % 2.0**100)

testpass = True
p2_rng = ((30, 63, 127), (62, 63, 127))[is_64bit][ll_type]
for i in range(0, p2_rng):
bitcnt = len(bin(int(2.0 ** i))) - 3
bitcnt = len(bin(int(2.0**i))) - 3
if i != bitcnt:
print("fail: 2.**%u was %u bits long" % (i, bitcnt))
testpass = False
Expand All @@ -53,7 +53,7 @@
testpass = True
p10_rng = 9 if (ll_type == 0 and ~is_64bit) else 11
for i in range(0, p10_rng):
digcnt = len(str(int(10.0 ** i))) - 1
digcnt = len(str(int(10.0**i))) - 1
if i != digcnt:
print("fail: 10.**%u was %u digits long" % (i, digcnt))
testpass = False
Expand All @@ -72,28 +72,28 @@ def fp2int_test(num, name, should_fail):
if ll_type != 2:
if ll_type == 0:
if is_64bit:
neg_bad_fp = -1.00000005 * 2.0 ** 62.0
pos_bad_fp = 2.0 ** 62.0
neg_good_fp = -(2.0 ** 62.0)
pos_good_fp = 0.99999993 * 2.0 ** 62.0
neg_bad_fp = -1.00000005 * 2.0**62.0
pos_bad_fp = 2.0**62.0
neg_good_fp = -(2.0**62.0)
pos_good_fp = 0.99999993 * 2.0**62.0
else:
neg_bad_fp = -1.00000005 * 2.0 ** 30.0
pos_bad_fp = 2.0 ** 30.0
neg_good_fp = -(2.0 ** 30.0)
pos_good_fp = 0.9999999499 * 2.0 ** 30.0
neg_bad_fp = -1.00000005 * 2.0**30.0
pos_bad_fp = 2.0**30.0
neg_good_fp = -(2.0**30.0)
pos_good_fp = 0.9999999499 * 2.0**30.0
else:
neg_bad_fp = -0.51 * 2.0 ** 64.0
pos_bad_fp = 2.0 ** 63.0
neg_good_fp = -(2.0 ** 63.0)
pos_good_fp = 1.9999998 * 2.0 ** 62.0
neg_bad_fp = -0.51 * 2.0**64.0
pos_bad_fp = 2.0**63.0
neg_good_fp = -(2.0**63.0)
pos_good_fp = 1.9999998 * 2.0**62.0

fp2int_test(neg_bad_fp, "neg bad", True)
fp2int_test(pos_bad_fp, "pos bad", True)
fp2int_test(neg_good_fp, "neg good", False)
fp2int_test(pos_good_fp, "pos good", False)
else:
fp2int_test(-1.999999879 * 2.0 ** 127.0, "large neg", False)
fp2int_test(1.999999879 * 2.0 ** 127.0, "large pos", False)
fp2int_test(-1.999999879 * 2.0**127.0, "large neg", False)
fp2int_test(1.999999879 * 2.0**127.0, "large pos", False)

fp2int_test(float("inf"), "inf test", True)
fp2int_test(float("nan"), "NaN test", True)
Expand Down
2 changes: 1 addition & 1 deletion tests/float/inf_nan_arith.py
Expand Up @@ -14,7 +14,7 @@
except ZeroDivisionError:
print(" / ZeroDivisionError")
try:
print(" ** pow", x ** y, pow(x, y))
print(" ** pow", x**y, pow(x, y))
except ZeroDivisionError:
print(" ** pow ZeroDivisionError")
print(" == != < <= > >=", x == y, x != y, x < y, x <= y, x > y, x >= y)
2 changes: 1 addition & 1 deletion tests/float/int_big_float.py
Expand Up @@ -19,7 +19,7 @@
print("%.5g" % (i * 1.2j).imag)

# negative power should produce float
print("%.5g" % (i ** -1))
print("%.5g" % (i**-1))
print("%.5g" % ((2 + i - i) ** -3))

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/float/int_divzero.py
Expand Up @@ -4,6 +4,6 @@
print("ZeroDivisionError")

try:
0 ** -1
0**-1
except ZeroDivisionError:
print("ZeroDivisionError")
2 changes: 1 addition & 1 deletion tests/float/int_power.py
@@ -1,7 +1,7 @@
# negative power should produce float

x = 2
print(x ** -2)
print(x**-2)

x = 3
x **= -2
Expand Down
2 changes: 1 addition & 1 deletion tests/micropython/import_mpy_native_x64.py
Expand Up @@ -9,7 +9,7 @@
print("SKIP")
raise SystemExit

if not (usys.platform == "linux" and usys.maxsize > 2 ** 32):
if not (usys.platform == "linux" and usys.maxsize > 2**32):
print("SKIP")
raise SystemExit

Expand Down
12 changes: 6 additions & 6 deletions tests/misc/rge_sm.py
Expand Up @@ -52,12 +52,12 @@ def series(self):
# couplings are: g1, g2, g3 of U(1), SU(2), SU(3); yt (top Yukawa), lambda (Higgs quartic)
# see arxiv.org/abs/0812.4950, eqs 10-15
sysSM = (
lambda *a: 41.0 / 96.0 / math.pi ** 2 * a[1] ** 3, # g1
lambda *a: -19.0 / 96.0 / math.pi ** 2 * a[2] ** 3, # g2
lambda *a: -42.0 / 96.0 / math.pi ** 2 * a[3] ** 3, # g3
lambda *a: 41.0 / 96.0 / math.pi**2 * a[1] ** 3, # g1
lambda *a: -19.0 / 96.0 / math.pi**2 * a[2] ** 3, # g2
lambda *a: -42.0 / 96.0 / math.pi**2 * a[3] ** 3, # g3
lambda *a: 1.0
/ 16.0
/ math.pi ** 2
/ math.pi**2
* (
9.0 / 2.0 * a[4] ** 3
- 8.0 * a[3] ** 2 * a[4]
Expand All @@ -66,7 +66,7 @@ def series(self):
), # yt
lambda *a: 1.0
/ 16.0
/ math.pi ** 2
/ math.pi**2
* (
24.0 * a[5] ** 2
+ 12.0 * a[4] ** 2 * a[5]
Expand Down Expand Up @@ -137,5 +137,5 @@ def singleTraj(system, trajStart, h=0.02, tend=1.0):

# initial conditions at M_Z
singleTraj(
sysSM, [0.354, 0.654, 1.278, 0.983, 0.131], h=0.5, tend=math.log(10 ** 17)
sysSM, [0.354, 0.654, 1.278, 0.983, 0.131], h=0.5, tend=math.log(10**17)
) # true values
2 changes: 1 addition & 1 deletion tests/perf_bench/bm_chaos.py
Expand Up @@ -15,7 +15,7 @@ def __init__(self, x=0, y=0, z=0):
self.z = z

def Mag(self):
return math.sqrt(self.x ** 2 + self.y ** 2 + self.z ** 2)
return math.sqrt(self.x**2 + self.y**2 + self.z**2)

def dist(self, other):
return math.sqrt(
Expand Down
8 changes: 4 additions & 4 deletions tests/perf_bench/misc_raytrace.py
Expand Up @@ -22,7 +22,7 @@ def __mul__(self, rhs):
return Vec(self.x * rhs, self.y * rhs, self.z * rhs)

def length(self):
return (self.x ** 2 + self.y ** 2 + self.z ** 2) ** 0.5
return (self.x**2 + self.y**2 + self.z**2) ** 0.5

def normalise(self):
l = self.length()
Expand Down Expand Up @@ -87,12 +87,12 @@ class Sphere:
def __init__(self, surface, centre, radius):
self.surface = surface
self.centre = centre
self.radsq = radius ** 2
self.radsq = radius**2

def intersect(self, ray):
v = self.centre - ray.p
b = v.dot(ray.d)
det = b ** 2 - v.dot(v) + self.radsq
det = b**2 - v.dot(v) + self.radsq
if det > 0:
det **= 0.5
t1 = b - det
Expand Down Expand Up @@ -180,7 +180,7 @@ def trace_ray(scene, ray, depth):
if ndotl > 0:
col += light_col * surf.diffuse * ndotl
if ldotv > 0:
col += light_col * surf.specular * ldotv ** surf.spec_idx
col += light_col * surf.specular * ldotv**surf.spec_idx

# Reflections
if depth > 0 and surf.reflect > 0:
Expand Down

0 comments on commit ab2923d

Please sign in to comment.