Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

[pre-commit.ci] pre-commit suggestions (#3109)

pre-commit-ci[bot]fed52224f0ef
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 01153b809..221f0cbba 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -15,7 +15,7 @@ repos:
exclude: ^$|.devcontainer
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.8.6
+ rev: v0.9.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
diff --git a/conftest.py b/conftest.py
index 06ff5653c..b3216d1c7 100644
--- a/conftest.py
+++ b/conftest.py
@@ -288,7 +288,7 @@ def pytest_report_header(config):
if "cpu" in env_info:
desired_cpu_info = ["Model name", "Architecture", "CPU(s)", "Thread(s) per core", "CPU max MHz", "CPU min MHz"]
cpu_info = "cpu info:\n" + "\n".join(
- f'\t- {i}: {env_info["cpu"][i]}' for i in desired_cpu_info if i in env_info["cpu"]
+ f"\t- {i}: {env_info['cpu'][i]}" for i in desired_cpu_info if i in env_info["cpu"]
)
else:
cpu_info = ""
@@ -303,7 +303,7 @@ main deps:
- torch-{torch.__version__}
- commit: {torch.version.git_version}
- cuda: {torch.version.cuda}
- - nvidia-driver: {env_info['nvidia'] if 'nvidia' in env_info else None}
+ - nvidia-driver: {env_info["nvidia"] if "nvidia" in env_info else None}
x deps:
- {accelerate_info}
dev deps:
diff --git a/kornia/contrib/object_detection.py b/kornia/contrib/object_detection.py
index a4c75200f..ff99a8c4c 100644
--- a/kornia/contrib/object_detection.py
+++ b/kornia/contrib/object_detection.py
@@ -51,8 +51,7 @@ class BoundingBox(BoundingBoxBase):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
warnings.warn(
- "BoundingBox is deprecated and will be removed in v0.8.0. "
- "Use kornia.models.detection.BoundingBox instead.",
+ "BoundingBox is deprecated and will be removed in v0.8.0. Use kornia.models.detection.BoundingBox instead.",
DeprecationWarning,
stacklevel=1,
)
diff --git a/kornia/enhance/adjust.py b/kornia/enhance/adjust.py
index 7ef1d52eb..93a533a38 100644
--- a/kornia/enhance/adjust.py
+++ b/kornia/enhance/adjust.py
@@ -810,7 +810,7 @@ def posterize(input: Tensor, bits: Union[int, Tensor]) -> Tensor:
if bits.shape != input.shape[: len(bits.shape)]:
raise AssertionError(
"Batch and channel must be equal between bits and input. "
- f"Got {bits.shape}, {input.shape[:len(bits.shape)]}."
+ f"Got {bits.shape}, {input.shape[: len(bits.shape)]}."
)
_input = input.view(-1, *input.shape[len(bits.shape) :])
_bits = bits.flatten()
diff --git a/kornia/feature/lightglue.py b/kornia/feature/lightglue.py
index 2c25cdc8e..8bdacc1cc 100644
--- a/kornia/feature/lightglue.py
+++ b/kornia/feature/lightglue.py
@@ -130,8 +130,7 @@ class Attention(Module):
super().__init__()
if allow_flash and not FLASH_AVAILABLE:
warnings.warn(
- "FlashAttention is not available. For optimal speed, "
- "consider installing torch >= 2.0 or flash-attn.",
+ "FlashAttention is not available. For optimal speed, consider installing torch >= 2.0 or flash-attn.",
stacklevel=2,
)
self.enable_flash = allow_flash and FLASH_AVAILABLE
diff --git a/tests/augmentation/test_augmentation.py b/tests/augmentation/test_augmentation.py
index 6aa2d703e..6c6ed75be 100644
--- a/tests/augmentation/test_augmentation.py
+++ b/tests/augmentation/test_augmentation.py
@@ -171,15 +171,15 @@ class CommonTests(BaseTester):
############################################################################################################
def _test_smoke_implementation(self, params):
- assert issubclass(
- self._augmentation_cls, AugmentationBase2D
- ), f"{self._augmentation_cls} is not a subclass of AugmentationBase2D"
+ assert issubclass(self._augmentation_cls, AugmentationBase2D), (
+ f"{self._augmentation_cls} is not a subclass of AugmentationBase2D"
+ )
# Can be instantiated
augmentation = self._create_augmentation_from_params(**params)
- assert issubclass(
- type(augmentation), AugmentationBase2D
- ), f"{type(augmentation)} is not a subclass of AugmentationBase2D"
+ assert issubclass(type(augmentation), AugmentationBase2D), (
+ f"{type(augmentation)} is not a subclass of AugmentationBase2D"
+ )
# generate_parameters can be called and returns the correct amount of parameters
batch_shape = (4, 3, 5, 6)
@@ -2047,9 +2047,7 @@ class TestRandomBrightness(BaseTester):
@pytest.mark.xfail(reason="might fail under windows OS due to printing preicision.")
def test_smoke(self):
f = RandomBrightness(brightness=(0.5, 1.5))
- repr = (
- "RandomBrightness(brightness_factor=tensor([0.5000, 1.5000]), " "p=1.0, p_batch=1.0, same_on_batch=False))"
- )
+ repr = "RandomBrightness(brightness_factor=tensor([0.5000, 1.5000]), p=1.0, p_batch=1.0, same_on_batch=False))"
assert str(f.__repr__) == repr
def test_random_brighness_identity(self, device, dtype):
@@ -2160,7 +2158,7 @@ class TestRandomContrast(BaseTester):
@pytest.mark.xfail(reason="might fail under windows OS due to printing preicision.")
def test_smoke(self):
f = RandomContrast(contrast=(0.7, 1.3))
- repr = "RandomContrast(contrast=tensor([0.7000, 1.3000]), " "p=1.0, p_batch=1.0, same_on_batch=False)"
+ repr = "RandomContrast(contrast=tensor([0.7000, 1.3000]), p=1.0, p_batch=1.0, same_on_batch=False)"
assert str(f) == repr
def test_random_contrast_identity(self, device, dtype):
@@ -2271,7 +2269,7 @@ class TestRandomHue(BaseTester):
@pytest.mark.xfail(reason="might fail under windows OS due to printing preicision.")
def test_smoke(self):
f = RandomHue(hue=(-0.2, 0.3))
- repr = "RandomHue(hue=tensor([-0.2000, 0.3000]), " "p=1.0, p_batch=1.0, same_on_batch=False)"
+ repr = "RandomHue(hue=tensor([-0.2000, 0.3000]), p=1.0, p_batch=1.0, same_on_batch=False)"
assert str(f) == repr
def test_random_hue_identity(self, device, dtype):
@@ -2388,7 +2386,7 @@ class TestRandomSaturation(BaseTester):
@pytest.mark.xfail(reason="might fail under windows OS due to printing preicision.")
def test_smoke(self):
f = RandomSaturation(saturation=(0.5, 1.5))
- repr = "RandomSaturation(hue=tensor([0.5000, 1.5000]), " "p=1.0, p_batch=1.0, same_on_batch=False)"
+ repr = "RandomSaturation(hue=tensor([0.5000, 1.5000]), p=1.0, p_batch=1.0, same_on_batch=False)"
assert str(f) == repr
def test_random_saturation_identity(self, device, dtype):
@@ -4376,7 +4374,7 @@ class TestNormalize(BaseTester):
@pytest.mark.xfail(reason="might fail under windows OS due to printing preicision.")
def test_smoke(self, device, dtype):
f = Normalize(mean=torch.tensor([1.0]), std=torch.tensor([1.0]))
- repr = "Normalize(mean=torch.tensor([1.]), std=torch.tensor([1.]), p=1., p_batch=1.0, " "same_on_batch=False)"
+ repr = "Normalize(mean=torch.tensor([1.]), std=torch.tensor([1.]), p=1., p_batch=1.0, same_on_batch=False)"
assert str(f) == repr
@pytest.mark.parametrize(
@@ -4454,7 +4452,7 @@ class TestDenormalize(BaseTester):
@pytest.mark.xfail(reason="might fail under windows OS due to printing preicision.")
def test_smoke(self, device, dtype):
f = Denormalize(mean=torch.tensor([1.0]), std=torch.tensor([1.0]))
- repr = "Denormalize(mean=torch.tensor([1.]), std=torch.tensor([1.]), p=1., p_batch=1.0, " "same_on_batch=False)"
+ repr = "Denormalize(mean=torch.tensor([1.]), std=torch.tensor([1.]), p=1., p_batch=1.0, same_on_batch=False)"
assert str(f) == repr
def test_random_denormalize(self, device, dtype):
diff --git a/tests/augmentation/test_random_generator.py b/tests/augmentation/test_random_generator.py
index 371b64668..17749af26 100644
--- a/tests/augmentation/test_random_generator.py
+++ b/tests/augmentation/test_random_generator.py
@@ -221,8 +221,10 @@ class TestColorJiggleGen(RandomGeneratorBaseTests):
"hue_factor",
"saturation_factor",
"order",
- }, "Redundant keys found apart from \
+ }, (
+ "Redundant keys found apart from \
'brightness_factor', 'contrast_factor', 'hue_factor', 'saturation_factor', 'order'"
+ )
assert_close(
jitter_params["brightness_factor"],
@@ -295,8 +297,10 @@ class TestColorJiggleGen(RandomGeneratorBaseTests):
"hue_factor",
"saturation_factor",
"order",
- }, "Redundant keys found apart from \
+ }, (
+ "Redundant keys found apart from \
'brightness_factor', 'contrast_factor', 'hue_factor', 'saturation_factor', 'order'"
+ )
assert_close(
jitter_params["brightness_factor"],
@@ -508,8 +512,10 @@ class TestColorJitterGen(RandomGeneratorBaseTests):
"hue_factor",
"saturation_factor",
"order",
- }, "Redundant keys found apart from \
+ }, (
+ "Redundant keys found apart from \
'brightness_factor', 'contrast_factor', 'hue_factor', 'saturation_factor', 'order'"
+ )
assert_close(
jitter_params["brightness_factor"],
diff --git a/tests/geometry/transform/test_affine.py b/tests/geometry/transform/test_affine.py
index a6d717e86..a4891a869 100644
--- a/tests/geometry/transform/test_affine.py
+++ b/tests/geometry/transform/test_affine.py
@@ -587,7 +587,7 @@ class TestAffine2d(BaseTester):
def test_affine_rotate(self, device, dtype):
# TODO: Remove when #666 is implemented
if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA." "See https://github.com/kornia/kornia/issues/666")
+ pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
torch.manual_seed(0)
angle = torch.rand(1, device=device, dtype=dtype) * 90.0
input = torch.rand(1, 2, 3, 4, device=device, dtype=dtype)
@@ -600,7 +600,7 @@ class TestAffine2d(BaseTester):
def test_affine_translate(self, device, dtype):
# TODO: Remove when #666 is implemented
if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA." "See https://github.com/kornia/kornia/issues/666")
+ pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
torch.manual_seed(0)
translation = torch.rand(1, 2, device=device, dtype=dtype) * 2.0
input = torch.rand(1, 2, 3, 4, device=device, dtype=dtype)
@@ -613,7 +613,7 @@ class TestAffine2d(BaseTester):
def test_affine_scale(self, device, dtype):
# TODO: Remove when #666 is implemented
if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA." "See https://github.com/kornia/kornia/issues/666")
+ pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
torch.manual_seed(0)
_scale_factor = torch.rand(1, device=device, dtype=dtype) * 2.0
scale_factor = torch.stack([_scale_factor, _scale_factor], dim=1)
@@ -641,7 +641,7 @@ class TestAffine2d(BaseTester):
def test_affine_rotate_translate(self, device, dtype):
# TODO: Remove when #666 is implemented
if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA." "See https://github.com/kornia/kornia/issues/666")
+ pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
batch_size = 2
input = torch.tensor(