Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix(core): bind eye_like and vec_like, and check __all__ names resolve (#4143)

Chen Yufan0743e29e9547
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d424d007a..47f8a7a5d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -238,6 +238,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
call now samples on the image's device and matches the same-device result (`extract_patches_simple` previously
built the full sampling grid on the LAF's device).
+* `AUTUMN` is dropped from `kornia.color.__all__` (#4143). The class was deprecated in 0.7.2 in favour of
+ `ColorMap(base='autumn')` and removed by #3432, which left the `__all__` entry behind. Since that removal
+ `from kornia.color import AUTUMN` has raised `AttributeError` and `from kornia.color import *` has failed on
+ it, so nothing that works today stops working β€” the entry named a binding that no longer existed. Callers
+ still reaching for the class should use `ColorMap(base='autumn')`.
+
* The shape guards of `normalize_homography` and `denormalize_homography` now reject everything but a
`(3, 3)`/`(B, 3, 3)` matrix, and `normalize_homography3d`'s everything but a `(4, 4)`/`(B, 4, 4)` one (#3999).
A rank-4 input used to pass the guard and come back with its rank unchanged β€”
diff --git a/kornia/color/__init__.py b/kornia/color/__init__.py
index eca2845fd..55e3f8021 100644
--- a/kornia/color/__init__.py
+++ b/kornia/color/__init__.py
@@ -72,7 +72,6 @@ from .yuv import (
)
__all__ = [
- "AUTUMN",
"CFA",
"ApplyColorMap",
"BgrToGrayscale",
diff --git a/kornia/core/__init__.py b/kornia/core/__init__.py
index 0f68e5a87..439edcd6b 100644
--- a/kornia/core/__init__.py
+++ b/kornia/core/__init__.py
@@ -29,6 +29,7 @@ from .mixin import (
ONNXRuntimeMixin,
)
from .module import ImageModule, ImageSequential
+from .ops import eye_like, vec_like
from .safetensors import load_safetensors
from .tensor_wrapper import TensorWrapper
diff --git a/tests/api_surface.json b/tests/api_surface.json
index b27c75f82..96a6d00ee 100644
--- a/tests/api_surface.json
+++ b/tests/api_surface.json
@@ -88,7 +88,6 @@
"container"
],
"kornia.color": [
- "AUTUMN",
"ApplyColorMap",
"BgrToGrayscale",
"BgrToRgb",
diff --git a/tests/test_api_surface.py b/tests/test_api_surface.py
index c73387fd6..2cbbe6bff 100644
--- a/tests/test_api_surface.py
+++ b/tests/test_api_surface.py
@@ -30,8 +30,11 @@ Additions are fine and do not fail the test; run this file with
``regenerate()`` below) whenever new public API lands.
"""
+import contextlib
import importlib
import json
+import pkgutil
+import warnings
from pathlib import Path
import pytest
@@ -86,6 +89,56 @@ def test_no_public_name_removed(module_name):
)
+def _modules_declaring_all() -> list:
+ """Every importable ``kornia`` submodule that declares ``__all__``.
+
+ The inventory tracks the stable-core modules, but an unbound name is a problem
+ wherever it sits: the breakage that motivated this guard (#4026, the
+ ComfyUI-LTXVideo report in #3986) was in ``kornia.geometry.transform.pyramid``,
+ which the inventory does not cover. Walking the package finds every module that
+ declares a public surface, costs a fraction of a second, and needs no upkeep as
+ modules come and go.
+ """
+ import kornia
+
+ found = []
+ for info in pkgutil.walk_packages(kornia.__path__, "kornia."):
+ # Optional extras and backends are out of scope for this guard, so a module that
+ # cannot be imported here is skipped rather than failing the sweep.
+ with contextlib.suppress(Exception):
+ mod = importlib.import_module(info.name)
+ if getattr(mod, "__all__", None) is not None:
+ found.append(info.name)
+ return sorted(found)
+
+
[email protected]("module_name", _modules_declaring_all())
+def test_public_names_resolve(module_name):
+ """
+ Every name in ``__all__`` has to be bound in its module.
+
+ An unbound name breaks ``from <module> import *`` for everyone, and
+ ``test_no_public_name_removed`` cannot see it: the surface that test compares is
+ ``__all__`` itself, so a name whose binding was dropped still reads as present.
+ """
+ mod = importlib.import_module(module_name)
+ declared = mod.__all__
+
+ with warnings.catch_warnings():
+ # ``hasattr`` runs module-level ``__getattr__``, which is how the deprecated
+ # ``kornia.utils`` re-exports announce themselves. Keep the probe quiet so it
+ # does not emit a DeprecationWarning per run just by looking.
+ warnings.simplefilter("ignore")
+ unbound = sorted(name for name in declared if not hasattr(mod, name))
+
+ assert not unbound, (
+ f"{module_name}.__all__ lists names that are not bound in the module: "
+ f"{unbound}. `from {module_name} import *` raises AttributeError on the "
+ "first of them. Either restore the binding or drop the name from __all__ "
+ "and from tests/api_surface.json in the same PR."
+ )
+
+
if __name__ == "__main__":
regenerate()
print(f"regenerated {INVENTORY}")