Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Use `is` to compare type of objects (#1086)

deepsource-autofix[bot]4c8762399064
diff --git a/kornia/augmentation/augmentation3d.py b/kornia/augmentation/augmentation3d.py
index 5fefd7480..61d89a565 100644
--- a/kornia/augmentation/augmentation3d.py
+++ b/kornia/augmentation/augmentation3d.py
@@ -910,7 +910,7 @@ class RandomCrop3D(AugmentationBase3D):
params: Optional[Dict[str, torch.Tensor]] = None,
return_transform: Optional[bool] = None,
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
- if type(input) == tuple:
+ if type(input) is tuple:
input = (self.precrop_padding(input[0]), input[1])
else:
input = self.precrop_padding(input) # type:ignore
diff --git a/kornia/augmentation/random_generator/random_generator.py b/kornia/augmentation/random_generator/random_generator.py
index 628e5fa2f..f552cb7f7 100644
--- a/kornia/augmentation/random_generator/random_generator.py
+++ b/kornia/augmentation/random_generator/random_generator.py
@@ -141,7 +141,7 @@ def random_perspective_generator(
distortion_scale.dim() == 0 and 0 <= distortion_scale <= 1
), f"'distortion_scale' must be a scalar within [0, 1]. Got {distortion_scale}."
assert (
- type(height) == int and height > 0 and type(width) == int and width > 0
+ type(height) is int and height > 0 and type(width) is int and width > 0
), f"'height' and 'width' must be integers. Got {height}, {width}."
start_points: torch.Tensor = torch.tensor(
@@ -485,7 +485,7 @@ def random_crop_size_generator(
_joint_range_check(scale, "scale")
_joint_range_check(ratio, "ratio")
assert (
- len(size) == 2 and type(size[0]) == int and size[1] > 0 and type(size[1]) == int and size[1] > 0
+ len(size) == 2 and type(size[0]) is int and size[1] > 0 and type(size[1]) is int and size[1] > 0
), f"'height' and 'width' must be integers. Got {size}."
_device, _dtype = _extract_device_dtype([scale, ratio])
@@ -570,7 +570,7 @@ def random_rectangles_params_generator(
_common_param_check(batch_size, same_on_batch)
_device, _dtype = _extract_device_dtype([ratio, scale])
assert (
- type(height) == int and height > 0 and type(width) == int and width > 0
+ type(height) is int and height > 0 and type(width) is int and width > 0
), f"'height' and 'width' must be integers. Got {height}, {width}."
assert (
isinstance(value, (int, float)) and value >= 0 and value <= 1
@@ -687,7 +687,7 @@ def center_crop_generator(
if not isinstance(size, (tuple, list)) and len(size) == 2:
raise ValueError("Input size must be a tuple/list of length 2. Got {}".format(size))
assert (
- type(height) == int and height > 0 and type(width) == int and width > 0
+ type(height) is int and height > 0 and type(width) is int and width > 0
), f"'height' and 'width' must be integers. Got {height}, {width}."
assert (
height >= size[0] and width >= size[1]
@@ -1048,7 +1048,7 @@ def random_cutmix_generator(
cut_size = torch.as_tensor([0.0, 1.0] if cut_size is None else cut_size, device=device, dtype=dtype)
assert num_mix >= 1 and isinstance(num_mix, (int,)), f"`num_mix` must be an integer greater than 1. Got {num_mix}."
assert (
- type(height) == int and height > 0 and type(width) == int and width > 0
+ type(height) is int and height > 0 and type(width) is int and width > 0
), f"'height' and 'width' must be integers. Got {height}, {width}."
_joint_range_check(cut_size, 'cut_size', bounds=(0, 1))
_common_param_check(batch_size, same_on_batch)
diff --git a/kornia/augmentation/random_generator/random_generator3d.py b/kornia/augmentation/random_generator/random_generator3d.py
index a8596e196..c8fa6a73c 100644
--- a/kornia/augmentation/random_generator/random_generator3d.py
+++ b/kornia/augmentation/random_generator/random_generator3d.py
@@ -93,7 +93,7 @@ def random_affine_generator3d(
The generated random numbers are not reproducible across different devices and dtypes.
"""
assert (
- type(depth) == int and depth > 0 and type(height) == int and height > 0 and type(width) == int and width > 0
+ type(depth) is int and depth > 0 and type(height) is int and height > 0 and type(width) is int and width > 0
), f"'depth', 'height' and 'width' must be integers. Got {depth}, {height}, {width}."
_device, _dtype = _extract_device_dtype([degrees, translate, scale, shears])
@@ -263,7 +263,7 @@ def center_crop_generator3d(
if not isinstance(size, (tuple, list)) and len(size) == 3:
raise ValueError("Input size must be a tuple/list of length 3. Got {}".format(size))
assert (
- type(depth) == int and depth > 0 and type(height) == int and height > 0 and type(width) == int and width > 0
+ type(depth) is int and depth > 0 and type(height) is int and height > 0 and type(width) is int and width > 0
), f"'depth', 'height' and 'width' must be integers. Got {depth}, {height}, {width}."
assert (
depth >= size[0] and height >= size[1] and width >= size[2]
diff --git a/kornia/augmentation/utils/param_validation.py b/kornia/augmentation/utils/param_validation.py
index dac5f15f4..7085e426c 100644
--- a/kornia/augmentation/utils/param_validation.py
+++ b/kornia/augmentation/utils/param_validation.py
@@ -5,9 +5,9 @@ import torch
def _common_param_check(batch_size: int, same_on_batch: Optional[bool] = None):
"""Valid batch_size and same_on_batch params."""
- assert type(batch_size) == int and batch_size >= 0, f"`batch_size` shall be a positive integer. Got {batch_size}."
+ assert type(batch_size) is int and batch_size >= 0, f"`batch_size` shall be a positive integer. Got {batch_size}."
if same_on_batch is not None:
- assert type(same_on_batch) == bool, f"`same_on_batch` shall be boolean. Got {same_on_batch}."
+ assert type(same_on_batch) is bool, f"`same_on_batch` shall be boolean. Got {same_on_batch}."
def _range_bound(
diff --git a/kornia/constants.py b/kornia/constants.py
index eb80e3884..fbf92c288 100644
--- a/kornia/constants.py
+++ b/kornia/constants.py
@@ -12,21 +12,21 @@ T = TypeVar('T', bound='ConstantBase')
class ConstantBase:
@classmethod
def get(cls, value: Union[str, int, T]) -> T: # type: ignore
- if type(value) == str:
+ if type(value) is str:
return cls[value.upper()] # type: ignore
- if type(value) == int:
+ if type(value) is int:
return cls(value) # type: ignore
- if type(value) == cls:
+ if type(value) is cls:
return value # type: ignore
raise TypeError()
class EnumMetaFlags(EnumMeta):
def __contains__(self, other: Union[str, int, T]) -> bool: # type: ignore
- if type(other) == str:
+ if type(other) is str:
other = cast(str, other)
return any(val.name == other.upper() for val in self) # type: ignore
- if type(other) == int:
+ if type(other) is int:
return any(val.value == other for val in self) # type: ignore
return any(val == other for val in self) # type: ignore