π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
refactor: resolve and enforce Ruff SIM105 (#5437)
Alex7a50a2309200
diff --git a/conftest.py b/conftest.pyindex cd5d2b8d3..a8f7b46c8 100644--- a/conftest.py+++ b/conftest.py@@ -15,6 +15,7 @@# limitations under the License.#+import contextlibimport osimport randomimport subprocess@@ -242,10 +243,8 @@ def _validate_complete_known_failure_run(config, option: str) -> None:for arg in config.args:target = Path(arg.split("::", maxsplit=1)[0])if target.is_absolute():- try:+ with contextlib.suppress(ValueError):target = target.relative_to(config.rootpath)- except ValueError:- passnormalized_args.add(target.as_posix().removeprefix("./").rstrip("/"))if normalized_args != {"tests"}:raise pytest.UsageError(f"{option} requires exactly the full tests/ target")diff --git a/kornia/augmentation/container/image.py b/kornia/augmentation/container/image.pyindex d646e6719..6185b85bd 100644--- a/kornia/augmentation/container/image.py+++ b/kornia/augmentation/container/image.py@@ -332,10 +332,11 @@ class ImageSequential(ImageSequentialBase, ImageModuleForSequentialMixIn):for (_, module), param in zip(named_modules, params if params is not None else []):if isinstance(module, K.GeometricAugmentationBase2D) and isinstance(param.data, dict):ori_shape = input.shape- try:+ # Ignore error for 5-dim video. Keep try/except: Dynamo on torch 2.5.1 cannot trace+ # contextlib.suppress, so it would break the graph under torch.compile.+ try: # noqa: SIM105input = module.transform_tensor(input)except ValueError:- # Ignore error for 5-dim videopass# Standardize shapeif recompute:diff --git a/pyproject.toml b/pyproject.tomlindex a2f8772e0..c113fd8b8 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -228,6 +228,7 @@ select = ["RUF", # Ruff-specific rules"S", # flake8-bandit"SIM103", # needless-bool+ "SIM105", # suppressible-exception"SIM114", # if-with-same-arms"SIM115", # open-file-with-context-handler"SIM117", # multiple-with-statementsdiff --git a/testing/half_precision_ci.py b/testing/half_precision_ci.pyindex 1eabdd899..84ee55dff 100644--- a/testing/half_precision_ci.py+++ b/testing/half_precision_ci.py@@ -17,6 +17,7 @@from __future__ import annotations+import contextlibimport hashlibimport osimport platform@@ -571,10 +572,8 @@ def _normalize_selector(selector: str, rootpath: Path | None = None) -> str:path, separator, node = selector.partition("::")selector_path = Path(path)if selector_path.is_absolute() and rootpath is not None:- try:+ with contextlib.suppress(ValueError):selector_path = selector_path.relative_to(rootpath)- except ValueError:- passnormalized_path = selector_path.as_posix().removeprefix("./").rstrip("/")return f"{normalized_path}::{node}" if separator else normalized_pathdiff --git a/tests/core/test_weights_prefetch.py b/tests/core/test_weights_prefetch.pyindex 8933c7c58..5c432631b 100644--- a/tests/core/test_weights_prefetch.py+++ b/tests/core/test_weights_prefetch.py@@ -61,6 +61,7 @@ provided every copy of the commit hash agrees, whichfrom __future__ import annotations+import contextlibimport functoolsimport importlib.utilimport re@@ -364,10 +365,8 @@ def _lightglue_sources(monkeypatch) -> dict[str, tuple[str, list[str]]]:monkeypatch.setattr(lightglue_mod, "load_state_dict_from_url", _capture)for feature in LIGHTGLUE_FEATURES:pending.append(feature)- try:+ with contextlib.suppress(_Captured):LightGlue(feature)- except _Captured:- passreturn captured