From 02a54aa50ea1e6594f34a8f30949e1bb93036c15 Mon Sep 17 00:00:00 2001 From: Tushar Saini Date: Tue, 4 Jun 2024 14:24:38 +0530 Subject: [PATCH] [UPD] update typing_extension to typing --- retailtree/logics/vp_tree.py | 4 ++-- retailtree/retailtree.py | 7 ++++--- retailtree/structs/annotation_struct.py | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/retailtree/logics/vp_tree.py b/retailtree/logics/vp_tree.py index 1c3f221..ef70fdb 100644 --- a/retailtree/logics/vp_tree.py +++ b/retailtree/logics/vp_tree.py @@ -1,6 +1,6 @@ import math import statistics as stats -from typing_extensions import Callable +from typing import Callable from retailtree.structs.annotation_struct import Annotation @@ -60,7 +60,7 @@ def _is_leaf(self): def get_all_in_range(self, query, max_distance): # type: (tuple[float, float], float) -> list[tuple[float, Annotation]] - neighbors = list() # type: list[tuple[float, Annotation]] + neighbors = list() # type: list[tuple[float, Annotation]] nodes_to_visit = [(self, 0)] while len(nodes_to_visit) > 0: diff --git a/retailtree/retailtree.py b/retailtree/retailtree.py index e2cfbe2..a49b0dc 100644 --- a/retailtree/retailtree.py +++ b/retailtree/retailtree.py @@ -1,7 +1,7 @@ import math from random import sample import numpy as np -from typing_extensions import Callable, Literal +from typing import Callable from retailtree.structs.annotation_struct import Annotation from retailtree.logics.vp_tree import VPTree @@ -186,7 +186,7 @@ def neighbors(self, id, radius=1): return result_lst def TBLR(self, id, radius=1, overlap=0.5): - # type:(int, int, float) -> (dict[str, int | bool] | Literal['SKU is absent in annotation bucket']) + # type:(int, int, float) -> (dict[str, int | bool] | str) """ Computes top, bottom, left, and right connections for a given annotation within a specified radius. @@ -198,8 +198,9 @@ def TBLR(self, id, radius=1, overlap=0.5): - overlap (float, optional): The overlap percentage used to compute connections. Defaults to 0.5. Returns: - - dict: A dictionary containing top, bottom, left, and right connections of the given annotation. + - dict OR str: A dictionary containing top, bottom, left, and right connections of the given annotation. Each connection is represented by the ID of the connected annotation, or False if no connection exists. + If the SKU is not present in the bucket, a string with value 'SKU is absent in annotation bucket' is returned. Examples: Example usages of TBLR: diff --git a/retailtree/structs/annotation_struct.py b/retailtree/structs/annotation_struct.py index 2c2ad54..f4de548 100644 --- a/retailtree/structs/annotation_struct.py +++ b/retailtree/structs/annotation_struct.py @@ -1,5 +1,5 @@ -from typing_extensions import Any +from typing import Any class Annotation: @@ -25,7 +25,7 @@ class Annotation: """ - def __init__(self, id, x_min, y_min, x_max, y_max, label = None, metadata = None): + def __init__(self, id, x_min, y_min, x_max, y_max, label=None, metadata=None): # type:(int, float, float, float, float, Any , dict[Any, Any]) -> None self.__id = int(id) self.__x_min = float(x_min) @@ -41,10 +41,10 @@ def __init__(self, id, x_min, y_min, x_max, y_max, label = None, metadata = None self.__width = None # TODO Check compatibility for older versions of python - self.right = None # type: Annotation - self.left = None # type: Annotation - self.top = None # type: Annotation - self.bottom = None # type: Annotation + self.right = None # type: Annotation + self.left = None # type: Annotation + self.top = None # type: Annotation + self.bottom = None # type: Annotation self.overlap_right = 0 self.overlap_top = 0