Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit d816031

Browse files
authored
MAINT: run black on all files in CI (#64)
In #63 black was run on `setup.py`. Follow up by running black on all files in CI. Do an inital pass over the entire codebase so that the CI check will pass.
1 parent b230e32 commit d816031

13 files changed

+54
-53
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ install:
1717

1818
script:
1919
- flake8
20-
- black --check numpy-stubs
20+
- black --check .
2121
- py.test
2222

2323
cache:

runtests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
def main():
1212
subprocess.run(
13-
[sys.executable, '-m', 'pip', 'install', STUBS_ROOT],
13+
[sys.executable, "-m", "pip", "install", STUBS_ROOT],
1414
capture_output=True,
1515
check=True,
1616
)
1717
sys.exit(pytest.main([STUBS_ROOT] + sys.argv[1:]))
1818

1919

20-
if __name__ == '__main__':
20+
if __name__ == "__main__":
2121
main()

scripts/find_ufuncs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ def main():
1010

1111
ufunc_stubs = []
1212
for ufunc in set(ufuncs):
13-
ufunc_stubs.append(f'{ufunc.__name__}: ufunc')
13+
ufunc_stubs.append(f"{ufunc.__name__}: ufunc")
1414
ufunc_stubs.sort()
1515

1616
for stub in ufunc_stubs:
1717
print(stub)
1818

1919

20-
if __name__ == '__main__':
20+
if __name__ == "__main__":
2121
main()

tests/fail/scalars.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
np.datetime64(0) # E: non-matching overload
3030

31-
dt_64 = np.datetime64(0, 'D')
32-
td_64 = np.timedelta64(1, 'h')
31+
dt_64 = np.datetime64(0, "D")
32+
td_64 = np.timedelta64(1, "h")
3333

3434
dt_64 + dt_64 # E: Unsupported operand types
3535

tests/fail/ufuncs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
22

3-
np.sin.nin + 'foo' # E: Unsupported operand types
4-
np.sin(1, foo='bar') # E: Unexpected keyword argument
5-
np.sin(1, extobj=['foo', 'foo', 'foo']) # E: incompatible type
3+
np.sin.nin + "foo" # E: Unsupported operand types
4+
np.sin(1, foo="bar") # E: Unexpected keyword argument
5+
np.sin(1, extobj=["foo", "foo", "foo"]) # E: incompatible type

tests/fail/warnings_and_errors.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
np.AxisError(1.0) # E: Argument 1 to "AxisError" has incompatible type
44
np.AxisError(1, ndim=2.0) # E: Argument "ndim" to "AxisError" has incompatible type
5-
np.AxisError(2, msg_prefix=404) # E: Argument "msg_prefix" to "AxisError" has incompatible type
5+
np.AxisError(
6+
2, msg_prefix=404 # E: Argument "msg_prefix" to "AxisError" has incompatible type
7+
)

tests/pass/scalars.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ def __float__(self):
5353

5454
# Time structures
5555
np.datetime64()
56-
np.datetime64(0, 'D')
57-
np.datetime64('2019')
58-
np.datetime64('2019', 'D')
56+
np.datetime64(0, "D")
57+
np.datetime64("2019")
58+
np.datetime64("2019", "D")
5959

6060
np.timedelta64()
6161
np.timedelta64(0)
62-
np.timedelta64(0, 'D')
62+
np.timedelta64(0, "D")
6363

64-
dt_64 = np.datetime64(0, 'D')
65-
td_64 = np.timedelta64(1, 'h')
64+
dt_64 = np.datetime64(0, "D")
65+
td_64 = np.timedelta64(1, "h")
6666

6767
dt_64 + td_64
6868
dt_64 - dt_64
6969
dt_64 - td_64
7070

7171
td_64 + td_64
7272
td_64 - td_64
73-
td_64 / 1.
73+
td_64 / 1.0
7474
td_64 / td_64
7575
td_64 % td_64

tests/pass/simple.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
# Basic checks
88
array = np.array([1, 2])
9+
10+
911
def ndarray_func(x):
1012
# type: (np.ndarray) -> np.ndarray
1113
return x
14+
15+
1216
ndarray_func(np.array([1, 2]))
1317
array == 1
1418
array.dtype == float
@@ -21,38 +25,40 @@ def ndarray_func(x):
2125
np.dtype(float)
2226
np.dtype(np.float64)
2327
np.dtype(None)
24-
np.dtype('float64')
28+
np.dtype("float64")
2529
np.dtype(np.dtype(float))
26-
np.dtype(('U', 10))
30+
np.dtype(("U", 10))
2731
np.dtype((np.int32, (2, 2)))
2832
# Define the arguments on the previous line to prevent bidirectional
2933
# type inference in mypy from broadening the types.
30-
two_tuples_dtype = [('R', 'u1'), ('G', 'u1'), ('B', 'u1')]
34+
two_tuples_dtype = [("R", "u1"), ("G", "u1"), ("B", "u1")]
3135
np.dtype(two_tuples_dtype)
3236

33-
three_tuples_dtype = [('R', 'u1', 1)]
37+
three_tuples_dtype = [("R", "u1", 1)]
3438
np.dtype(three_tuples_dtype)
3539

36-
mixed_tuples_dtype = [('R', 'u1'), ('G', np.unicode_, 1)]
40+
mixed_tuples_dtype = [("R", "u1"), ("G", np.unicode_, 1)]
3741
np.dtype(mixed_tuples_dtype)
3842

39-
shape_tuple_dtype = [('R', 'u1', (2, 2))]
43+
shape_tuple_dtype = [("R", "u1", (2, 2))]
4044
np.dtype(shape_tuple_dtype)
4145

42-
shape_like_dtype = [('R', 'u1', (2, 2)), ('G', np.unicode_, 1)]
46+
shape_like_dtype = [("R", "u1", (2, 2)), ("G", np.unicode_, 1)]
4347
np.dtype(shape_like_dtype)
4448

45-
object_dtype = [('field1', object)]
49+
object_dtype = [("field1", object)]
4650
np.dtype(object_dtype)
4751

48-
np.dtype({'col1': ('U10', 0), 'col2': ('float32', 10)})
49-
np.dtype((np.int32, {'real': (np.int16, 0), 'imag': (np.int16, 2)}))
52+
np.dtype({"col1": ("U10", 0), "col2": ("float32", 10)})
53+
np.dtype((np.int32, {"real": (np.int16, 0), "imag": (np.int16, 2)}))
5054
np.dtype((np.int32, (np.int8, 4)))
5155

5256
# Iteration and indexing
5357
def iterable_func(x):
5458
# type: (Iterable) -> Iterable
5559
return x
60+
61+
5662
iterable_func(array)
5763
[element for element in array]
5864
iter(array)

tests/pass/ufuncs.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
np.sin(1)
44
np.sin([1, 2, 3])
55
np.sin(1, out=np.empty(1))
6-
np.matmul(
7-
np.ones((2, 2, 2)),
8-
np.ones((2, 2, 2)),
9-
axes=[(0, 1), (0, 1), (0, 1)],
10-
)
11-
np.sin(1, signature='D')
6+
np.matmul(np.ones((2, 2, 2)), np.ones((2, 2, 2)), axes=[(0, 1), (0, 1), (0, 1)])
7+
np.sin(1, signature="D")
128
np.sin(1, extobj=[16, 1, lambda: None])
139
np.sin(1) + np.sin(1)
1410
np.sin.types[0]

tests/pass/warnings_and_errors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
np.AxisError(1)
44
np.AxisError(1, ndim=2)
55
np.AxisError(1, ndim=None)
6-
np.AxisError(1, ndim=2, msg_prefix='error')
6+
np.AxisError(1, ndim=2, msg_prefix="error")
77
np.AxisError(1, ndim=2, msg_prefix=None)

tests/reveal/ndarray_conversion.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
class SubArray(np.ndarray):
3939
pass
4040

41+
4142
reveal_type(nd.view()) # E: numpy.ndarray
4243
reveal_type(nd.view(np.int64)) # E: numpy.ndarray
4344
# replace `Any` with `numpy.matrix` when `matrix` will be added to stubs
@@ -51,4 +52,3 @@ class SubArray(np.ndarray):
5152

5253
# setflags does not return a value
5354
# fill does not return a value
54-

tests/reveal/scalars.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
reveal_type(x.real.real) # E: numpy.float32
99
reveal_type(x.real.imag) # E: numpy.float32
1010

11-
reveal_type(x.itemsize) # E: int
12-
reveal_type(x.shape) # E: tuple[builtins.int]
13-
reveal_type(x.strides) # E: tuple[builtins.int]
11+
reveal_type(x.itemsize) # E: int
12+
reveal_type(x.shape) # E: tuple[builtins.int]
13+
reveal_type(x.strides) # E: tuple[builtins.int]
1414

1515
# Time structures
16-
dt = np.datetime64(0, 'D')
17-
td = np.timedelta64(0, 'D')
16+
dt = np.datetime64(0, "D")
17+
td = np.timedelta64(0, "D")
1818

1919
reveal_type(dt + td) # E: numpy.datetime64
20-
reveal_type(dt + 1) # E: numpy.datetime64
20+
reveal_type(dt + 1) # E: numpy.datetime64
2121
reveal_type(dt - dt) # E: numpy.timedelta64
22-
reveal_type(dt - 1) # E: numpy.timedelta64
22+
reveal_type(dt - 1) # E: numpy.timedelta64
2323

2424
reveal_type(td + td) # E: numpy.timedelta64
25-
reveal_type(td + 1) # E: numpy.timedelta64
25+
reveal_type(td + 1) # E: numpy.timedelta64
2626
reveal_type(td - td) # E: numpy.timedelta64
27-
reveal_type(td - 1) # E: numpy.timedelta64
28-
reveal_type(td / 1.) # E: numpy.timedelta64
27+
reveal_type(td - 1) # E: numpy.timedelta64
28+
reveal_type(td / 1.0) # E: numpy.timedelta64
2929
reveal_type(td / td) # E: float
3030
reveal_type(td % td) # E: numpy.timedelta64

tests/test_stubs.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_test_cases(directory):
2626
continue
2727
if py_version_number == 3 and skip_py3:
2828
continue
29-
py2_arg = ['--py2'] if py_version_number == 2 else []
29+
py2_arg = ["--py2"] if py_version_number == 2 else []
3030

3131
yield pytest.param(
3232
fullpath,
@@ -40,10 +40,7 @@ def get_test_cases(directory):
4040
def test_success(path, py2_arg):
4141
stdout, stderr, exitcode = api.run([path] + py2_arg)
4242
assert exitcode == 0, stdout
43-
assert re.match(
44-
r'Success: no issues found in \d+ source files?',
45-
stdout.strip(),
46-
)
43+
assert re.match(r"Success: no issues found in \d+ source files?", stdout.strip())
4744

4845

4946
@pytest.mark.parametrize("path,py2_arg", get_test_cases(FAIL_DIR))
@@ -58,7 +55,7 @@ def test_fail(path, py2_arg):
5855
errors = defaultdict(lambda: "")
5956
error_lines = stdout.rstrip("\n").split("\n")
6057
assert re.match(
61-
r'Found \d+ errors? in \d+ files? \(checked \d+ source files?\)',
58+
r"Found \d+ errors? in \d+ files? \(checked \d+ source files?\)",
6259
error_lines[-1].strip(),
6360
)
6461
for error_line in error_lines[:-1]:
@@ -80,7 +77,7 @@ def test_fail(path, py2_arg):
8077
assert lineno in errors, f'Extra error "{marker}"'
8178
assert marker in errors[lineno]
8279
else:
83-
pytest.fail(f'Error {repr(errors[lineno])} not found')
80+
pytest.fail(f"Error {repr(errors[lineno])} not found")
8481

8582

8683
@pytest.mark.parametrize("path,py2_arg", get_test_cases(REVEAL_DIR))

0 commit comments

Comments
 (0)