Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Add bandit B101 test and fix (#1248)

Edgar Riba4558fecf2e5f
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 790683d67..4c22e042e 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -51,11 +51,11 @@ repos:
rev: 1.7.0
hooks:
- id: bandit
+ language_version: python3
+ exclude: ^test/
args:
- - --recursive
- - --skip
- - "B101,B311,B404,B602,B603,B607"
- - .
+ - -s
+ - "B311,B404,B602,B603,B607"
- repo: https://github.com/myint/docformatter
rev: v1.4
diff --git a/kornia/augmentation/container/patch.py b/kornia/augmentation/container/patch.py
index 8adf90580..084411332 100644
--- a/kornia/augmentation/container/patch.py
+++ b/kornia/augmentation/container/patch.py
@@ -109,11 +109,12 @@ class PatchSequential(ImageSequential):
# will only apply [1, 4] augmentations per patch
_random_apply = (1, 4)
elif patchwise_apply and random_apply is False:
- assert len(args) == grid_size[0] * grid_size[1], (
- "The number of processing modules must be equal with grid size."
- f"Got {len(args)} and {grid_size[0] * grid_size[1]}. "
- "Please set random_apply = True or patchwise_apply = False."
- )
+ if len(args) != grid_size[0] * grid_size[1]:
+ raise ValueError(
+ "The number of processing modules must be equal with grid size."
+ f"Got {len(args)} and {grid_size[0] * grid_size[1]}. "
+ "Please set random_apply = True or patchwise_apply = False."
+ )
_random_apply = random_apply
elif patchwise_apply and isinstance(random_apply, (int, tuple)):
raise ValueError(f"Only boolean value allowed when `patchwise_apply` is set to True. Got {random_apply}.")
@@ -122,7 +123,8 @@ class PatchSequential(ImageSequential):
super().__init__(
*args, same_on_batch=same_on_batch, return_transform=False, keepdim=keepdim, random_apply=_random_apply
)
- assert padding in ["same", "valid"], f"`padding` must be either `same` or `valid`. Got {padding}."
+ if padding not in ("same", "valid"):
+ raise ValueError(f"`padding` must be either `same` or `valid`. Got {padding}.")
self.grid_size = grid_size
self.padding = padding
self.patchwise_apply = patchwise_apply