Skip to content

Commit

Permalink
Add ARG ruff rules (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
durandtibo authored Mar 1, 2024
1 parent 321da2d commit c8e5a35
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 167 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ syntax = "google"
lint.select = [
"A", # builtins
"ANN", # annotations
"ARG", # flake8-unused-arguments
"B", # bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
Expand Down Expand Up @@ -181,6 +182,7 @@ lint.ignore = [
lint.fixable = [
"A",
"ANN",
"ARG",
"B",
"BLE",
"C4",
Expand Down
14 changes: 7 additions & 7 deletions src/coola/equality/handlers/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def __repr__(self) -> str:

def handle(
self,
actual: Any,
expected: Any,
config: EqualityConfig,
actual: Any, # noqa: ARG002
expected: Any, # noqa: ARG002
config: EqualityConfig, # noqa: ARG002
) -> bool:
return False

Expand Down Expand Up @@ -96,13 +96,13 @@ def __repr__(self) -> str:

def handle(
self,
actual: Any,
expected: Any,
config: EqualityConfig,
actual: Any, # noqa: ARG002
expected: Any, # noqa: ARG002
config: EqualityConfig, # noqa: ARG002
) -> bool:
return True

def set_next_handler(self, handler: BaseEqualityHandler) -> None:
def set_next_handler(self, handler: BaseEqualityHandler) -> None: # noqa: ARG002
pass # Do nothing because the next handler is never called.


Expand Down
6 changes: 5 additions & 1 deletion src/coola/formatters/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def equal(self, other: Any) -> bool:
return self._max_characters == other._max_characters

def format(
self, summarizer: BaseSummarizer, value: Any, depth: int = 0, max_depth: int = 1
self,
summarizer: BaseSummarizer, # noqa: ARG002
value: Any,
depth: int = 0,
max_depth: int = 1,
) -> str:
if depth >= max_depth:
return self._format(str(value))
Expand Down
6 changes: 5 additions & 1 deletion src/coola/formatters/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def equal(self, other: Any) -> bool:
return self._show_data == other._show_data

def format(
self, summarizer: BaseSummarizer, value: np.ndarray, depth: int = 0, max_depth: int = 1
self,
summarizer: BaseSummarizer, # noqa: ARG002
value: np.ndarray,
depth: int = 0, # noqa: ARG002
max_depth: int = 1, # noqa: ARG002
) -> str:
if self._show_data:
return repr(value)
Expand Down
6 changes: 5 additions & 1 deletion src/coola/formatters/torch_.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def equal(self, other: Any) -> bool:
return self._show_data == other._show_data

def format(
self, summarizer: BaseSummarizer, value: torch.Tensor, depth: int = 0, max_depth: int = 1
self,
summarizer: BaseSummarizer, # noqa: ARG002
value: torch.Tensor,
depth: int = 0, # noqa: ARG002
max_depth: int = 1, # noqa: ARG002
) -> str:
if self._show_data:
return repr(value)
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def test_objects_are_equal_false_show_difference(


@pytest.mark.parametrize("example", COLLECTION_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def test_objects_are_equal_false_show_difference(

@jax_available
@pytest.mark.parametrize("example", JAX_ARRAY_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def test_objects_are_equal_false_show_difference(

@numpy_available
@pytest.mark.parametrize("example", NUMPY_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def test_objects_are_equal_false_show_difference(

@pandas_available
@pytest.mark.parametrize("example", PANDAS_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def test_objects_are_equal_false_show_difference(

@polars_available
@pytest.mark.parametrize("example", POLARS_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def test_objects_are_equal_false_show_difference(


@pytest.mark.parametrize("example", SCALAR_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def test_objects_are_equal_false_show_difference(

@torch_available
@pytest.mark.parametrize("example", TORCH_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 1 addition & 3 deletions tests/unit/equality/checks/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def test_objects_are_equal_false_show_difference(

@xarray_available
@pytest.mark.parametrize("example", XARRAY_EQUAL_TOLERANCE)
def test_objects_are_allclose_true_tolerance(
example: ExamplePair, caplog: pytest.LogCaptureFixture
) -> None:
def test_objects_are_allclose_true_tolerance(example: ExamplePair) -> None:
assert objects_are_allclose(
example.actual, example.expected, atol=example.atol, rtol=example.rtol
)
4 changes: 2 additions & 2 deletions tests/unit/equality/comparators/test_jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_jax_array_equality_comparator_equal_true_tolerance(
@jax_available
def test_jax_array_equality_comparator_no_jax() -> None:
with (
patch("coola.utils.imports.is_jax_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_jax_available", lambda: False),
pytest.raises(RuntimeError, match="`jax` package is required but not installed."),
):
JaxArrayEqualityComparator()
Expand All @@ -246,5 +246,5 @@ def test_get_type_comparator_mapping() -> None:


def test_get_type_comparator_mapping_no_jax() -> None:
with patch("coola.equality.comparators.jax_.is_jax_available", lambda *args, **kwargs: False):
with patch("coola.equality.comparators.jax_.is_jax_available", lambda: False):
assert get_type_comparator_mapping() == {}
8 changes: 3 additions & 5 deletions tests/unit/equality/comparators/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_numpy_array_equality_comparator_equal_true_tolerance(
@numpy_available
def test_numpy_array_equality_comparator_no_numpy() -> None:
with (
patch("coola.utils.imports.is_numpy_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_numpy_available", lambda: False),
pytest.raises(RuntimeError, match="`numpy` package is required but not installed."),
):
NumpyArrayEqualityComparator()
Expand Down Expand Up @@ -431,7 +431,7 @@ def test_numpy_masked_array_equality_comparator_equal_nan(
@numpy_available
def test_numpy_masked_array_equality_comparator_no_numpy() -> None:
with (
patch("coola.utils.imports.is_numpy_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_numpy_available", lambda: False),
pytest.raises(RuntimeError, match="`numpy` package is required but not installed."),
):
NumpyMaskedArrayEqualityComparator()
Expand All @@ -451,7 +451,5 @@ def test_get_type_comparator_mapping() -> None:


def test_get_type_comparator_mapping_no_numpy() -> None:
with patch(
"coola.equality.comparators.numpy_.is_numpy_available", lambda *args, **kwargs: False
):
with patch("coola.equality.comparators.numpy_.is_numpy_available", lambda: False):
assert get_type_comparator_mapping() == {}
8 changes: 3 additions & 5 deletions tests/unit/equality/comparators/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def test_pandas_dataframe_equality_comparator_equal_tolerance(
@pandas_available
def test_pandas_dataframe_equality_comparator_no_pandas() -> None:
with (
patch("coola.utils.imports.is_pandas_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_pandas_available", lambda: False),
pytest.raises(RuntimeError, match="`pandas` package is required but not installed."),
):
PandasDataFrameEqualityComparator()
Expand Down Expand Up @@ -486,7 +486,7 @@ def test_pandas_series_equality_comparator_equal_tolerance(
@pandas_available
def test_pandas_series_equality_comparator_no_pandas() -> None:
with (
patch("coola.utils.imports.is_pandas_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_pandas_available", lambda: False),
pytest.raises(RuntimeError, match="`pandas` package is required but not installed."),
):
PandasSeriesEqualityComparator()
Expand All @@ -506,7 +506,5 @@ def test_get_type_comparator_mapping() -> None:


def test_get_type_comparator_mapping_no_pandas() -> None:
with patch(
"coola.equality.comparators.pandas_.is_pandas_available", lambda *args, **kwargs: False
):
with patch("coola.equality.comparators.pandas_.is_pandas_available", lambda: False):
assert get_type_comparator_mapping() == {}
8 changes: 3 additions & 5 deletions tests/unit/equality/comparators/test_polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def test_polars_dataframe_equality_comparator_equal_tolerance(
@polars_available
def test_polars_dataframe_equality_comparator_no_polars() -> None:
with (
patch("coola.utils.imports.is_polars_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_polars_available", lambda: False),
pytest.raises(RuntimeError, match="`polars` package is required but not installed."),
):
PolarsDataFrameEqualityComparator()
Expand Down Expand Up @@ -488,7 +488,7 @@ def test_polars_series_equality_comparator_equal_tolerance(
@polars_available
def test_polars_series_equality_comparator_no_polars() -> None:
with (
patch("coola.utils.imports.is_polars_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_polars_available", lambda: False),
pytest.raises(RuntimeError, match="`polars` package is required but not installed."),
):
PolarsSeriesEqualityComparator()
Expand All @@ -508,7 +508,5 @@ def test_get_type_comparator_mapping() -> None:


def test_get_type_comparator_mapping_no_polars() -> None:
with patch(
"coola.equality.comparators.polars_.is_polars_available", lambda *args, **kwargs: False
):
with patch("coola.equality.comparators.polars_.is_polars_available", lambda: False):
assert get_type_comparator_mapping() == {}
8 changes: 3 additions & 5 deletions tests/unit/equality/comparators/test_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def test_tensor_packed_sequence_equality_comparator_equal_nan_false(
@torch_available
def test_tensor_packed_sequence_equality_comparator_no_torch() -> None:
with (
patch("coola.utils.imports.is_torch_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_torch_available", lambda: False),
pytest.raises(RuntimeError, match="`torch` package is required but not installed."),
):
TorchPackedSequenceEqualityComparator()
Expand Down Expand Up @@ -612,7 +612,7 @@ def test_torch_tensor_equality_comparator_true_tolerance(
@torch_available
def test_torch_tensor_equality_comparator_no_torch() -> None:
with (
patch("coola.utils.imports.is_torch_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_torch_available", lambda: False),
pytest.raises(RuntimeError, match="`torch` package is required but not installed."),
):
TorchTensorEqualityComparator()
Expand All @@ -632,7 +632,5 @@ def test_get_type_comparator_mapping() -> None:


def test_get_type_comparator_mapping_no_torch() -> None:
with patch(
"coola.equality.comparators.torch_.is_torch_available", lambda *args, **kwargs: False
):
with patch("coola.equality.comparators.torch_.is_torch_available", lambda: False):
assert get_type_comparator_mapping() == {}
10 changes: 4 additions & 6 deletions tests/unit/equality/comparators/test_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def test_xarray_data_array_equality_comparator_equal_true_tolerance(
@xarray_available
def test_xarray_data_array_equality_comparator_no_xarray() -> None:
with (
patch("coola.utils.imports.is_xarray_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_xarray_available", lambda: False),
pytest.raises(RuntimeError, match="`xarray` package is required but not installed."),
):
XarrayDataArrayEqualityComparator()
Expand Down Expand Up @@ -708,7 +708,7 @@ def test_xarray_dataset_equality_comparator_equal_true_tolerance(
@xarray_available
def test_xarray_dataset_equality_comparator_no_xarray() -> None:
with (
patch("coola.utils.imports.is_xarray_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_xarray_available", lambda: False),
pytest.raises(RuntimeError, match="`xarray` package is required but not installed."),
):
XarrayDatasetEqualityComparator()
Expand Down Expand Up @@ -833,7 +833,7 @@ def test_xarray_variable_equality_comparator_equal_true_tolerance(
@xarray_available
def test_xarray_variable_equality_comparator_no_xarray() -> None:
with (
patch("coola.utils.imports.is_xarray_available", lambda *args, **kwargs: False),
patch("coola.utils.imports.is_xarray_available", lambda: False),
pytest.raises(RuntimeError, match="`xarray` package is required but not installed."),
):
XarrayVariableEqualityComparator()
Expand All @@ -854,7 +854,5 @@ def test_get_type_comparator_mapping() -> None:


def test_get_type_comparator_mapping_no_xarray() -> None:
with patch(
"coola.equality.comparators.xarray_.is_xarray_available", lambda *args, **kwargs: False
):
with patch("coola.equality.comparators.xarray_.is_xarray_available", lambda: False):
assert get_type_comparator_mapping() == {}
Loading

0 comments on commit c8e5a35

Please sign in to comment.