Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

Do not ignore undefined names in Python code (#1210)

Christian Claussf272a788bc02
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 61d170d38..6c58b2ea0 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -19,6 +19,7 @@ repos:
rev: 21.7b0
hooks:
- id: black
+ args: [--diff]
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
diff --git a/kornia/geometry/camera/pinhole.py b/kornia/geometry/camera/pinhole.py
index 11744d802..0d3d4e653 100644
--- a/kornia/geometry/camera/pinhole.py
+++ b/kornia/geometry/camera/pinhole.py
@@ -501,7 +501,7 @@ def get_optical_pose_base(pinholes: torch.Tensor) -> torch.Tensor:
raise AssertionError(pinholes.shape)
optical_pose_parent = pinholes[..., 6:]
# TODO: where is rtvec_to_pose?
- return rtvec_to_pose(optical_pose_parent) # type: ignore
+ return rtvec_to_pose(optical_pose_parent) # noqa: F821 type: ignore
def homography_i_H_ref(pinhole_i: torch.Tensor, pinhole_ref: torch.Tensor) -> torch.Tensor:
diff --git a/setup.cfg b/setup.cfg
index 0f0060e43..61961a7d2 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -20,7 +20,6 @@ license_file = LICENSE
[flake8]
max-line-length = 120
ignore =
- W503
E203
E305
E402
@@ -30,9 +29,9 @@ ignore =
F401
F403
F405
- F821
- F841
F811
+ F841
+ W503
exclude = docs/src
[mypy]
diff --git a/setup.py b/setup.py
index 315df88d0..389f42eac 100644
--- a/setup.py
+++ b/setup.py
@@ -2,6 +2,7 @@
#
import distutils.command.clean
import glob
+import io
import os
import shutil
import subprocess
diff --git a/test/augmentation/test_augmentation_3d.py b/test/augmentation/test_augmentation_3d.py
index e7c180b2c..e78541ec3 100644
--- a/test/augmentation/test_augmentation_3d.py
+++ b/test/augmentation/test_augmentation_3d.py
@@ -8,6 +8,7 @@ from torch.autograd import gradcheck
import kornia
import kornia.testing as utils # test utils
from kornia.augmentation import (
+ RandomCrop,
RandomCrop3D,
RandomDepthicalFlip3D,
RandomEqualize3D,
diff --git a/test/augmentation/test_random_generator.py b/test/augmentation/test_random_generator.py
index 087b7bcd5..d32967f12 100644
--- a/test/augmentation/test_random_generator.py
+++ b/test/augmentation/test_random_generator.py
@@ -554,7 +554,7 @@ class TestRandomCropSizeGen(RandomGeneratorBaseTests):
size=size,
scale=scale.to(device=device, dtype=dtype),
ratio=ratio.to(device=device, dtype=dtype),
- same_on_batch=same_on_batch,
+ same_on_batch=same_on_batch, # noqa: F821 raises NameError
)
def test_random_gen(self, device, dtype):
@@ -653,7 +653,7 @@ class TestRandomRectangleGen(RandomGeneratorBaseTests):
scale=scale.to(device=device, dtype=dtype),
ratio=ratio.to(device=device, dtype=dtype),
value=value,
- same_on_batch=same_on_batch,
+ same_on_batch=same_on_batch, # noqa: F821 raises NameError
)
def test_random_gen(self, device, dtype):
@@ -854,7 +854,7 @@ class TestRandomSolarizeGen(RandomGeneratorBaseTests):
def test_invalid_param_combinations(self, thresholds, additions, device, dtype):
with pytest.raises(Exception):
random_solarize_generator(
- batch_size=batch_size,
+ batch_size=batch_size, # noqa: F821 raises NameError
thresholds=thresholds.to(device=device, dtype=dtype),
additions=additions.to(device=device, dtype=dtype),
)
@@ -915,7 +915,9 @@ class TestRandomPosterizeGen(RandomGeneratorBaseTests):
def test_invalid_param_combinations(self, bits, device, dtype):
with pytest.raises(Exception):
random_posterize_generator(
- batch_size=batch_size, bits=bits.to(device=device, dtype=dtype), same_on_batch=same_on_batch
+ batch_size=batch_size, # noqa: F821 raises NameError
+ bits=bits.to(device=device, dtype=dtype),
+ same_on_batch=same_on_batch, # noqa: F821 raises NameError
)
def test_random_gen(self, device, dtype):
@@ -952,7 +954,9 @@ class TestRandomSharpnessGen(RandomGeneratorBaseTests):
def test_invalid_param_combinations(self, sharpness, device, dtype):
with pytest.raises(Exception):
random_sharpness_generator(
- batch_size=batch_size, sharpness=sharpness.to(device=device, dtype=dtype), same_on_batch=same_on_batch
+ batch_size=batch_size, # noqa: F821 raises NameError
+ sharpness=sharpness.to(device=device, dtype=dtype),
+ same_on_batch=same_on_batch, # noqa: F821 raises NameError
)
def test_random_gen(self, device, dtype):
diff --git a/test/enhance/test_adjust.py b/test/enhance/test_adjust.py
index e80888424..7556f6a59 100644
--- a/test/enhance/test_adjust.py
+++ b/test/enhance/test_adjust.py
@@ -782,6 +782,7 @@ class TestSharpness(BaseTester):
@pytest.mark.jit
def test_jit(self, device, dtype):
op = torch.jit.script(kornia.enhance.adjust.sharpness)
+ op_script = torch.jit.script(op)
inputs = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
expected = op(input, 0.8)
actual = op_script(input, 0.8)
@@ -871,6 +872,7 @@ class TestSolarize(BaseTester):
@pytest.mark.jit
def test_jit(self, device, dtype):
op = torch.jit.script(kornia.enhance.adjust.solarize)
+ op_script = torch.jit.script(op)
inputs = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
expected = op(input, 0.8)
actual = op_script(input, 0.8)
@@ -951,6 +953,7 @@ class TestPosterize(BaseTester):
@pytest.mark.jit
def test_jit(self, device, dtype):
op = torch.jit.script(kornia.enhance.adjust.posterize)
+ op_script = torch.jit.script(op)
inputs = torch.rand(2, 1, 3, 3).to(device=device, dtype=dtype)
expected = op(input, 8)
actual = op_script(input, 8)
diff --git a/test/enhance/test_equalization.py b/test/enhance/test_equalization.py
index c36947311..7775cfd58 100644
--- a/test/enhance/test_equalization.py
+++ b/test/enhance/test_equalization.py
@@ -1,3 +1,5 @@
+from typing import Tuple
+
import pytest
import torch
from torch.autograd import gradcheck
diff --git a/test/geometry/epipolar/test_fundamental.py b/test/geometry/epipolar/test_fundamental.py
index edcc31f09..2b19fb940 100644
--- a/test/geometry/epipolar/test_fundamental.py
+++ b/test/geometry/epipolar/test_fundamental.py
@@ -1,3 +1,5 @@
+from typing import Dict
+
import pytest
import test_common as utils
import torch
diff --git a/test/geometry/epipolar/test_triangulation.py b/test/geometry/epipolar/test_triangulation.py
index e53789002..1ae568051 100644
--- a/test/geometry/epipolar/test_triangulation.py
+++ b/test/geometry/epipolar/test_triangulation.py
@@ -1,3 +1,5 @@
+from typing import Dict
+
import pytest
import torch
from torch.autograd import gradcheck