Skip to content

Commit

Permalink
Satisfy new flake8 type check rules (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv authored Oct 4, 2023
1 parent 233ef08 commit 2e52081
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cunumeric/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ def diagonal(
raise ValueError("extract can be true only for Ndim >=2")
axes = None
else:
if type(axis1) == int and type(axis2) == int:
if isinstance(axis1, int) and isinstance(axis2, int):
if axes is not None:
raise ValueError(
"Either axis1/axis2 or axes must be supplied"
Expand Down Expand Up @@ -3102,7 +3102,7 @@ def mean(
Multiple GPUs, Multiple CPUs
"""
if axis is not None and type(axis) != int:
if axis is not None and not isinstance(axis, int):
raise NotImplementedError(
"cunumeric.mean only supports int types for "
"'axis' currently"
Expand Down
4 changes: 2 additions & 2 deletions cunumeric/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4760,7 +4760,7 @@ def einsum_path(
"""
computed_operands = [convert_to_cunumeric_ndarray(op) for op in operands]
memory_limit = _builtin_max(op.size for op in computed_operands)
if type(optimize) == tuple:
if isinstance(optimize, tuple):
if len(optimize) != 2:
raise ValueError("einsum_path expects optimize tuples of size 2")
optimize, memory_limit = optimize
Expand All @@ -4771,7 +4771,7 @@ def einsum_path(
elif optimize in ["greedy", "optimal"]:
pass
elif (
type(optimize) == list
isinstance(optimize, list)
and len(optimize) > 1
and optimize[0] == "einsum_path"
):
Expand Down
6 changes: 3 additions & 3 deletions cunumeric/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ def deep_apply(obj: Any, func: Callable[[Any], Any]) -> Any:
primarily meant to be used for arguments of NumPy API calls, which
shouldn't nest their arrays very deep.
"""
if type(obj) == list:
if isinstance(obj, list):
return [deep_apply(x, func) for x in obj]
elif type(obj) == tuple:
elif isinstance(obj, tuple):
return tuple(deep_apply(x, func) for x in obj)
elif type(obj) == dict:
elif isinstance(obj, dict):
return {k: deep_apply(v, func) for k, v in obj.items()}
else:
return func(obj)
4 changes: 2 additions & 2 deletions tests/integration/test_prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_out_axis(self, size):
ndim = arr_np.ndim
for axis in range(-ndim + 1, ndim, 1):
out_shape = ()
if type(size) == tuple:
if isinstance(size, tuple):
out_shape_list = list(size)
del out_shape_list[axis]
out_shape = tuple(out_shape_list)
Expand All @@ -283,7 +283,7 @@ def test_out_axis_dtype(self, size):
ndim = arr_np.ndim
for axis in range(-ndim + 1, ndim, 1):
out_shape = ()
if type(size) == tuple:
if isinstance(size, tuple):
out_shape_list = list(size)
del out_shape_list[axis]
out_shape = tuple(out_shape_list)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_out_axis(self, size):
ndim = arr_np.ndim
for axis in range(-ndim + 1, ndim, 1):
out_shape = ()
if type(size) == tuple:
if isinstance(size, tuple):
out_shape_list = list(size)
del out_shape_list[axis]
out_shape = tuple(out_shape_list)
Expand All @@ -239,7 +239,7 @@ def test_out_axis_dtype(self, size):
ndim = arr_np.ndim
for axis in range(-ndim + 1, ndim, 1):
out_shape = ()
if type(size) == tuple:
if isinstance(size, tuple):
out_shape_list = list(size)
del out_shape_list[axis]
out_shape = tuple(out_shape_list)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_squeeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_array_basic(size):


@pytest.mark.parametrize(
"size", (s for s in SIZES if type(s) == tuple if 1 in s), ids=str
"size", (s for s in SIZES if isinstance(s, tuple) if 1 in s), ids=str
)
def test_num_axis(size):
a = np.random.randint(low=-10, high=10, size=size)
Expand All @@ -139,7 +139,7 @@ def test_num_axis(size):


@pytest.mark.parametrize(
"size", (s for s in SIZES if type(s) == tuple if 1 in s), ids=str
"size", (s for s in SIZES if isinstance(s, tuple) if 1 in s), ids=str
)
def test_array_axis(size):
a = np.random.randint(low=-10, high=10, size=size)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/cunumeric/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ def __array_prepare__(self):
return "I am now ready"

def foo(self, other):
assert type(self) == _Orig_ndarray
assert type(other) == _Orig_ndarray
assert type(self) == _Orig_ndarray # noqa
assert type(other) == _Orig_ndarray # noqa
return "original foo"

def bar(self, other):
Expand Down

0 comments on commit 2e52081

Please sign in to comment.