10000 MAINT: run black on all files in CI by person142 · Pull Request #64 · numpy/numpy-stubs · GitHub
[go: up one dir, main page]

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

MAINT: run black on all files in CI #64

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install:

script:
- flake8
- black --check numpy-stubs
- black --check .
- py.test

cache:
Expand Down
4 changes: 2 additions & 2 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

def main():
subprocess.run(
[sys.executable, '-m', 'pip', 'install', STUBS_ROOT],
[sys.executable, "-m", "pip", "install", STUBS_ROOT],
capture_output=True,
check=True,
)
sys.exit(pytest.main([STUBS_ROOT] + sys.argv[1:]))


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions scripts/find_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def main():

ufunc_stubs = []
for ufunc in set(ufuncs):
ufunc_stubs.append(f'{ufunc.__name__}: ufunc')
ufunc_stubs.append(f"{ufunc.__name__}: ufunc")
ufunc_stubs.sort()

for stub in ufunc_stubs:
print(stub)


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions tests/fail/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

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

dt_64 = np.datetime64(0, 'D')
td_64 = np.timedelta64(1, 'h')
dt_64 = np.datetime64(0, "D")
td_64 = np.timedelta64(1, "h")

dt_64 + dt_64 # E: Unsupported operand types

Expand Down
6 changes: 3 additions & 3 deletions tests/fail/ufuncs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np

np.sin.nin + 'foo' # E: Unsupported operand types
np.sin(1, foo='bar') # E: Unexpected keyword argument
np.sin(1, extobj=['foo', 'foo', 'foo']) # E: incompatible type
np.sin.nin + "foo" # E: Unsupported operand types
np.sin(1, foo="bar") # E: Unexpected keyword argument
np.sin(1, extobj=["foo", "foo", "foo"]) # E: incompatible type
4 changes: 3 additions & 1 deletion tests/fail/warnings_and_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

np.AxisError(1.0) # E: Argument 1 to "AxisError" has incompatible type
np.AxisError(1, ndim=2.0) # E: Argument "ndim" to "AxisError" has incompatible type
np.AxisError(2, msg_prefix=404) # E: Argument "msg_prefix" to "AxisError" has incompatible type
np.AxisError(
2, msg_prefix=404 # E: Argument "msg_prefix" to "AxisError" has incompatible type
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting one where you do have to modify the output black gives you a bit because the exact line number matters. I don't think this should be a huge inconvenience going forward though.

EDBE
)
14 changes: 7 additions & 7 deletions tests/pass/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ def __float__(self):

# Time structures
np.datetime64()
np.datetime64(0, 'D')
np.datetime64('2019')
np.datetime64('2019', 'D')
np.datetime64(0, "D")
np.datetime64("2019")
np.datetime64("2019", "D")

np.timedelta64()
np.timedelta64(0)
np.timedelta64(0, 'D')
np.timedelta64(0, "D")

dt_64 = np.datetime64(0, 'D')
td_64 = np.timedelta64(1, 'h')
dt_64 = np.datetime64(0, "D")
td_64 = np.timedelta64(1, "h")

dt_64 + td_64
dt_64 - dt_64
dt_64 - td_64

td_64 + td_64
td_64 - td_64
td_64 / 1.
td_64 / 1.0
td_64 / td_64
td_64 % td_64
26 changes: 16 additions & 10 deletions tests/pass/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

# Basic checks
array = np.array([1, 2])


def ndarray_func(x):
# type: (np.ndarray) -> np.ndarray
return x


ndarray_func(np.array([1, 2]))
array == 1
array.dtype == float
1E0A Expand All @@ -21,38 +25,40 @@ def ndarray_func(x):
np.dtype(float)
np.dtype(np.float64)
np.dtype(None)
np.dtype('float64')
np.dtype("float64")
np.dtype(np.dtype(float))
np.dtype(('U', 10))
np.dtype(("U", 10))
np.dtype((np.int32, (2, 2)))
# Define the arguments on the previous line to prevent bidirectional
# type inference in mypy from broadening the types.
two_tuples_dtype = [('R', 'u1'), ('G', 'u1'), ('B', 'u1')]
two_tuples_dtype = [("R", "u1"), ("G", "u1"), ("B", "u1")]
np.dtype(two_tuples_dtype)

three_tuples_dtype = [('R', 'u1', 1)]
three_tuples_dtype = [("R", "u1", 1)]
np.dtype(three_tuples_dtype)

mixed_tuples_dtype = [('R', 'u1'), ('G', np.unicode_, 1)]
mixed_tuples_dtype = [("R", "u1"), ("G", np.unicode_, 1)]
np.dtype(mixed_tuples_dtype)

shape_tuple_dtype = [('R', 'u1', (2, 2))]
shape_tuple_dtype = [("R", "u1", (2, 2))]
np.dtype(shape_tuple_dtype)

shape_like_dtype = [('R', 'u1', (2, 2)), ('G', np.unicode_, 1)]
shape_like_dtype = [("R", "u1", (2, 2)), ("G", np.unicode_, 1)]
np.dtype(shape_like_dtype)

object_dtype = [('field1', object)]
object_dtype = [("field1", object)]
np.dtype(object_dtype)

np.dtype({'col1': ('U10', 0), 'col2': ('float32', 10)})
np.dtype((np.int32, {'real': (np.int16, 0), 'imag': (np.int16, 2)}))
np.dtype({"col1": ("U10", 0), "col2": ("float32", 10)})
np.dtype((np.int32, {"real": (np.int16, 0), "imag": (np.int16, 2)}))
np.dtype((np.int32, (np.int8, 4)))

# Iteration and indexing
def iterable_func(x):
# type: (Iterable) -> Iterable
return x


iterable_func(array)
[element for element in array]
iter(array)
Expand Down
8 changes: 2 additions & 6 deletions tests/pass/ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
np.sin(1)
np.sin([1, 2, 3])
np.sin(1, out=np.empty(1))
np.matmul(
np.ones((2, 2, 2)),
np.ones((2, 2, 2)),
axes=[(0, 1), (0, 1), (0, 1)],
)
np.sin(1, signature='D')
np.matmul(np.ones((2, 2, 2)), np.ones((2, 2, 2)), axes=[(0, 1), (0, 1), (0, 1)])
np.sin(1, signature="D")
np.sin(1, extobj=[16, 1, lambda: None])
np.sin(1) + np.sin(1)
np.sin.types[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/pass/warnings_and_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
np.AxisError(1)
np.AxisError(1, ndim=2)
np.AxisError(1, ndim=None)
np.AxisError(1, ndim=2, msg_prefix='error')
np.AxisError(1, ndim=2, msg_prefix="error")
np.AxisError(1, ndim=2, msg_prefix=None)
2 changes: 1 addition & 1 deletion tests/reveal/ndarray_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
class SubArray(np.ndarray):
pass


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

# setflags does not return a value
# fill does not return a value

20 changes: 10 additions & 10 deletions tests/reveal/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
reveal_type(x.real.real) # E: numpy.float32
reveal_type(x.real.imag) # E: numpy.float32

reveal_type(x.itemsize) # E: int
reveal_type(x.shape) # E: tuple[builtins.int]
reveal_type(x.strides) # E: tuple[builtins.int]
reveal_type(x.itemsize) # E: int
reveal_type(x.shape) # E: tuple[builtins.int]
reveal_type(x.strides) # E: tuple[builtins.int]

# Time structures
dt = np.datetime64(0, 'D')
td = np.timedelta64(0, 'D')
dt = np.datetime64(0, "D")
td = np.timedelta64(0, "D")

reveal_type(dt + td) # E: numpy.datetime64
reveal_type(dt + 1) # E: numpy.datetime64
reveal_type(dt + 1) # E: numpy.datetime64
reveal_type(dt - dt) # E: numpy.timedelta64
reveal_type(dt - 1) # E: numpy.timedelta64
reveal_type(dt - 1) # E: numpy.timedelta64

reveal_type(td + td) # E: numpy.timedelta64
reveal_type(td + 1) # E: numpy.timedelta64
reveal_type(td + 1) # E: numpy.timedelta64
reveal_type(td - td) # E: numpy.timedelta64
reveal_type(td - 1) # E: numpy.timedelta64
reveal_type(td / 1.) # E: numpy.timedelta64
reveal_type(td - 1) # E: numpy.timedelta64
reveal_type(td / 1.0) # E: numpy.timedelta64
reveal_type(td / td) # E: float
reveal_type(td % td) # E: numpy.timedelta64
11 changes: 4 additions & 7 deletions tests/test_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_test_cases(directory):
continue
if py_version_number == 3 and skip_py3:
continue
py2_arg = ['--py2'] if py_version_number == 2 else []
py2_arg = ["--py2"] if py_version_number == 2 else []

yield pytest.param(
fullpath,
Expand All @@ -40,10 +40,7 @@ def get_test_cases(directory):
def test_success(path, py2_arg):
stdout, stderr, exitcode = api.run([path] + py2_arg)
assert exitcode == 0, stdout
assert re.match(
r'Success: no issues found in \d+ source files?',
stdout.strip(),
)
assert re.match(r"Success: no issues found in \d+ source files?", stdout.strip())


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


@pytest.mark.parametrize("path,py2_arg", get_test_cases(REVEAL_DIR))
Expand Down
0