Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

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

pre-commit-ci[bot]d22d1d426426
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 61d8a70d5..2f5c978ec 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -20,7 +20,7 @@ repos:
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.0.278
+ rev: v0.0.280
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
diff --git a/kornia/augmentation/_2d/intensity/random_rain.py b/kornia/augmentation/_2d/intensity/random_rain.py
index a849ced03..bbe5115d6 100644
--- a/kornia/augmentation/_2d/intensity/random_rain.py
+++ b/kornia/augmentation/_2d/intensity/random_rain.py
@@ -50,7 +50,7 @@ class RandomRain(IntensityAugmentationBase2D):
self, image: Tensor, params: dict[str, Tensor], flags: dict[str, Any], transform: Tensor | None = None
) -> Tensor:
# Check array and drops size
- KORNIA_CHECK(image.shape[1] == 3 or image.shape[1] == 1, "Number of color channels should be 1 or 3.")
+ KORNIA_CHECK(image.shape[1] in {3, 1}, "Number of color channels should be 1 or 3.")
KORNIA_CHECK(
bool(
torch.all(params['drop_height_factor'] <= image.shape[2])
diff --git a/kornia/augmentation/auto/rand_augment/rand_augment.py b/kornia/augmentation/auto/rand_augment/rand_augment.py
index 7b4332be8..da742c594 100644
--- a/kornia/augmentation/auto/rand_augment/rand_augment.py
+++ b/kornia/augmentation/auto/rand_augment/rand_augment.py
@@ -105,7 +105,7 @@ class RandAugment(PolicyAugmentBase):
mag = m * float(maxval - minval) + minval
mod_param = op.forward_parameters(batch_shape, mag=mag)
# Compose it
- param = ParamItem(name, [ParamItem(list(module.named_children())[0][0], mod_param)])
+ param = ParamItem(name, [ParamItem(next(iter(module.named_children()))[0], mod_param)])
params.append(param)
return params
diff --git a/kornia/augmentation/container/ops.py b/kornia/augmentation/container/ops.py
index febb73ee5..6db02e689 100644
--- a/kornia/augmentation/container/ops.py
+++ b/kornia/augmentation/container/ops.py
@@ -87,7 +87,7 @@ class AugmentationSequentialOps:
return InputSequentialOps
if data_key == DataKey.MASK:
return MaskSequentialOps
- if data_key == DataKey.BBOX or data_key == DataKey.BBOX_XYWH or data_key == DataKey.BBOX_XYXY:
+ if data_key in {DataKey.BBOX, DataKey.BBOX_XYWH, DataKey.BBOX_XYXY}:
return BoxSequentialOps
if data_key == DataKey.KEYPOINTS:
return KeypointSequentialOps
diff --git a/kornia/augmentation/utils/param_validation.py b/kornia/augmentation/utils/param_validation.py
index 73b2fb467..9777cbd44 100644
--- a/kornia/augmentation/utils/param_validation.py
+++ b/kornia/augmentation/utils/param_validation.py
@@ -139,38 +139,37 @@ def _tuple_range_reader(
f"Degrees must be a {list(target_shape)} tensor for the degree range for independent operation."
f"Got {input_range}"
)
- else:
- if isinstance(input_range, (float, int)): # noqa: PLR5501
- if input_range < 0:
- raise ValueError(f"If input_range is only one number it must be a positive number. Got{input_range}")
- input_range_tmp = tensor([-input_range, input_range], device=device, dtype=dtype).repeat(target_shape[0], 1)
-
- elif (
- isinstance(input_range, (tuple, list))
- and len(input_range) == 2
- and isinstance(input_range[0], (float, int))
- and isinstance(input_range[1], (float, int))
- ):
- input_range_tmp = tensor(input_range, device=device, dtype=dtype).repeat(target_shape[0], 1)
-
- elif (
- isinstance(input_range, (tuple, list))
- and len(input_range) == target_shape[0]
- and all(isinstance(x, (float, int)) for x in input_range)
- ):
- input_range_tmp = tensor([(-s, s) for s in input_range], device=device, dtype=dtype)
-
- elif (
- isinstance(input_range, (tuple, list))
- and len(input_range) == target_shape[0]
- and all(isinstance(x, (tuple, list)) for x in input_range)
- ):
- input_range_tmp = tensor(input_range, device=device, dtype=dtype)
+ elif isinstance(input_range, (float, int)):
+ if input_range < 0:
+ raise ValueError(f"If input_range is only one number it must be a positive number. Got{input_range}")
+ input_range_tmp = tensor([-input_range, input_range], device=device, dtype=dtype).repeat(target_shape[0], 1)
+
+ elif (
+ isinstance(input_range, (tuple, list))
+ and len(input_range) == 2
+ and isinstance(input_range[0], (float, int))
+ and isinstance(input_range[1], (float, int))
+ ):
+ input_range_tmp = tensor(input_range, device=device, dtype=dtype).repeat(target_shape[0], 1)
+
+ elif (
+ isinstance(input_range, (tuple, list))
+ and len(input_range) == target_shape[0]
+ and all(isinstance(x, (float, int)) for x in input_range)
+ ):
+ input_range_tmp = tensor([(-s, s) for s in input_range], device=device, dtype=dtype)
+
+ elif (
+ isinstance(input_range, (tuple, list))
+ and len(input_range) == target_shape[0]
+ and all(isinstance(x, (tuple, list)) for x in input_range)
+ ):
+ input_range_tmp = tensor(input_range, device=device, dtype=dtype)
- else:
- raise TypeError(
- "If not pass a tensor, it must be float, (float, float) for isotropic operation or a tuple of "
- f"{target_size} floats or {target_size} (float, float) for independent operation. Got {input_range}."
- )
+ else:
+ raise TypeError(
+ "If not pass a tensor, it must be float, (float, float) for isotropic operation or a tuple of "
+ f"{target_size} floats or {target_size} (float, float) for independent operation. Got {input_range}."
+ )
return input_range_tmp
diff --git a/kornia/geometry/transform/imgwarp.py b/kornia/geometry/transform/imgwarp.py
index f6b53215d..b66272e68 100644
--- a/kornia/geometry/transform/imgwarp.py
+++ b/kornia/geometry/transform/imgwarp.py
@@ -1268,10 +1268,8 @@ def homography_warp(
"""
if not src_homo_dst.device == patch_src.device:
raise TypeError(
- "Patch and homography must be on the same device. \
- Got patch.device: {} src_H_dst.device: {}.".format(
- patch_src.device, src_homo_dst.device
- )
+ f"Patch and homography must be on the same device. Got patch.device: {patch_src.device} "
+ f"src_H_dst.device: {src_homo_dst.device}."
)
if normalized_homography:
height, width = dsize
@@ -1333,10 +1331,8 @@ def homography_warp3d(
"""
if not src_homo_dst.device == patch_src.device:
raise TypeError(
- "Patch and homography must be on the same device. \
- Got patch.device: {} src_H_dst.device: {}.".format(
- patch_src.device, src_homo_dst.device
- )
+ f"Patch and homography must be on the same device. Got patch.device: {patch_src.device} "
+ f"src_H_dst.device: {src_homo_dst.device}."
)
depth, height, width = dsize