Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

refactor: import Self, ParamSpec, TypedDict and NotRequired from typing (#4328)

Dmytro Mishkina5df16b1b62f
diff --git a/kornia/augmentation/auto/operations/base.py b/kornia/augmentation/auto/operations/base.py
index 844fee4a5..82c75f63b 100644
--- a/kornia/augmentation/auto/operations/base.py
+++ b/kornia/augmentation/auto/operations/base.py
@@ -15,12 +15,11 @@
# limitations under the License.
#
-from typing import Callable, Dict, List, Optional, Tuple, TypeVar
+from typing import Callable, Dict, List, Optional, Self, Tuple, TypeVar
import torch
from torch import nn
from torch.distributions import Bernoulli, RelaxedBernoulli
-from typing_extensions import Self
from kornia.augmentation.base import _AugmentationBase
diff --git a/kornia/augmentation/container/ops.py b/kornia/augmentation/container/ops.py
index 31d3eab63..950b4749c 100644
--- a/kornia/augmentation/container/ops.py
+++ b/kornia/augmentation/container/ops.py
@@ -17,11 +17,10 @@
import copy
from abc import ABCMeta, abstractmethod
-from typing import Any, Callable, Dict, Generic, List, Optional, Type, TypeVar, Union
+from typing import Any, Callable, Dict, Generic, List, Optional, ParamSpec, Type, TypeVar, Union
import torch
from torch import nn
-from typing_extensions import ParamSpec
import kornia.augmentation as K
from kornia.augmentation.base import _AugmentationBase
diff --git a/kornia/feature/adalam/core.py b/kornia/feature/adalam/core.py
index c9bab83da..fb900d5a8 100644
--- a/kornia/feature/adalam/core.py
+++ b/kornia/feature/adalam/core.py
@@ -16,10 +16,9 @@
#
import math
-from typing import Optional, Tuple, Union
+from typing import NotRequired, Optional, Tuple, TypedDict, Union
import torch
-from typing_extensions import NotRequired, TypedDict
from .ransac import ransac
from .utils import dist_matrix, orientation_diff
diff --git a/kornia/feature/keynet.py b/kornia/feature/keynet.py
index 8e4280656..4511d0a4b 100644
--- a/kornia/feature/keynet.py
+++ b/kornia/feature/keynet.py
@@ -15,12 +15,11 @@
# limitations under the License.
#
-from typing import List, Optional
+from typing import List, Optional, TypedDict
import torch
import torch.nn.functional as F
from torch import nn
-from typing_extensions import TypedDict
from kornia.core.download import hf_url, load_state_dict_from_url
from kornia.filters import SpatialGradient
diff --git a/kornia/feature/scale_space_detector.py b/kornia/feature/scale_space_detector.py
index 622937804..e3ad31753 100644
--- a/kornia/feature/scale_space_detector.py
+++ b/kornia/feature/scale_space_detector.py
@@ -17,12 +17,11 @@
import math
from contextlib import nullcontext
-from typing import ContextManager, List, Optional, Tuple, Union
+from typing import ContextManager, List, Optional, Tuple, TypedDict, Union
import torch
import torch.nn.functional as F
from torch import nn
-from typing_extensions import TypedDict
from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPE
from kornia.geometry.subpix import (
diff --git a/tests/test_declared_imports.py b/tests/test_declared_imports.py
index 1f3e549aa..721d76dbd 100644
--- a/tests/test_declared_imports.py
+++ b/tests/test_declared_imports.py
@@ -77,8 +77,10 @@ DIST_TO_IMPORT = {
}
# Third-party modules that are allowed without appearing in ``pyproject.toml``: torch, which is a
-# declared runtime dependency, installs them, so anything that can import torch has them too.
-IMPLICIT_ALLOWED = {"typing_extensions"}
+# declared runtime dependency, installs them, so anything that can import torch has them too. Empty
+# since ``typing_extensions`` gave way to ``typing`` (every name kornia used is in the 3.11 stdlib);
+# an entry here is a package kornia imports on torch's word alone, so keep it empty when you can.
+IMPLICIT_ALLOWED: frozenset[str] = frozenset()
# Extras that exist for contributors, not for users of the library: nothing a user runs may depend
# on them, so they do not make a package "declared". Every other extra is user-facing and does.