diff --git a/src/dinglehopper/align.py b/src/dinglehopper/align.py index 1f7957a..cffdf98 100644 --- a/src/dinglehopper/align.py +++ b/src/dinglehopper/align.py @@ -1,6 +1,7 @@ import math import unicodedata from math import ceil +from typing import Union from rapidfuzz.distance import Levenshtein @@ -14,7 +15,7 @@ def align(t1, t2): return seq_align(s1, s2) -def score_hint(er: float, n: int) -> int | None: +def score_hint(er: float, n: int) -> Union[int, None]: """Calculate RapidFuzz score hint for a given error rate and count. Gives the score hint for the distance functions (= expected distance) or None if diff --git a/src/dinglehopper/character_error_rate.py b/src/dinglehopper/character_error_rate.py index 3b8c0cc..5e2e02c 100644 --- a/src/dinglehopper/character_error_rate.py +++ b/src/dinglehopper/character_error_rate.py @@ -1,5 +1,5 @@ import unicodedata -from typing import Tuple +from typing import List, Tuple from multimethod import multimethod from uniseg.graphemecluster import grapheme_clusters @@ -10,7 +10,7 @@ from .extracted_text import ExtractedText @multimethod def character_error_rate_n( - reference: list[str], compared: list[str] + reference: List[str], compared: List[str] ) -> Tuple[float, int]: """ Compute character error rate. diff --git a/src/dinglehopper/edit_distance.py b/src/dinglehopper/edit_distance.py index ef90d81..9f7d309 100644 --- a/src/dinglehopper/edit_distance.py +++ b/src/dinglehopper/edit_distance.py @@ -2,13 +2,14 @@ import unicodedata from multimethod import multimethod from rapidfuzz.distance import Levenshtein +from typing import List from uniseg.graphemecluster import grapheme_clusters from .extracted_text import ExtractedText @multimethod -def distance(seq1: list[str], seq2: list[str]): +def distance(seq1: List[str], seq2: List[str]): """Compute the Levenshtein edit distance between two lists of grapheme clusters. This assumes that the grapheme clusters are already normalized. diff --git a/src/dinglehopper/extracted_text.py b/src/dinglehopper/extracted_text.py index 28678e4..49882b7 100644 --- a/src/dinglehopper/extracted_text.py +++ b/src/dinglehopper/extracted_text.py @@ -4,7 +4,7 @@ import re import unicodedata from contextlib import suppress from itertools import repeat -from typing import Optional +from typing import Optional, List import attr import numpy as np @@ -135,7 +135,7 @@ class ExtractedText: segments = attr.ib(type=Optional[list], converter=attr.converters.optional(list)) joiner = attr.ib(type=Optional[str]) _text = attr.ib(type=Optional[str]) - _grapheme_clusters = attr.ib(type=Optional[list[str]]) + _grapheme_clusters = attr.ib(type=Optional[List[str]]) @segments.validator def check(self, _, value):