From 9a2a757c1418513c82c3ff289f23d4cd2312df2a Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 9 Jun 2025 15:22:52 -0400 Subject: [PATCH 1/2] Allow metric type to be exportable as TypeAlias. --- annoy/__init__.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/annoy/__init__.pyi b/annoy/__init__.pyi index 08adf4b9..6fd2cb80 100644 --- a/annoy/__init__.pyi +++ b/annoy/__init__.pyi @@ -2,12 +2,14 @@ from typing import Sized, overload from typing_extensions import Literal, Protocol +AnnoyMetric: TypeAlias = Literal["angular", "euclidean", "manhattan", "hamming", "dot"] + class _Vector(Protocol, Sized): def __getitem__(self, __index: int) -> float: ... class AnnoyIndex: f: int - def __init__(self, f: int, metric: Literal["angular", "euclidean", "manhattan", "hamming", "dot"]) -> None: ... + def __init__(self, f: int, metric: AnnoyMetric) -> None: ... def load(self, fn: str, prefault: bool = ...) -> Literal[True]: ... def save(self, fn: str, prefault: bool = ...) -> Literal[True]: ... @overload From 6433e68e93a238a21d74ec941e1fe43f0b28b73f Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 9 Jun 2025 15:24:23 -0400 Subject: [PATCH 2/2] Oops. Forgot to import TypeAlias. --- annoy/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/annoy/__init__.pyi b/annoy/__init__.pyi index 6fd2cb80..7c62c0cf 100644 --- a/annoy/__init__.pyi +++ b/annoy/__init__.pyi @@ -1,5 +1,5 @@ -from typing import Sized, overload +from typing import Sized, overload, TypeAlias from typing_extensions import Literal, Protocol AnnoyMetric: TypeAlias = Literal["angular", "euclidean", "manhattan", "hamming", "dot"]