From 3c499d9dfd45bd11397057213262469899028999 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 2 Oct 2022 10:06:27 +0200 Subject: [PATCH] sort imports --- .clang-format | 1 - _custom_build/backend.py | 9 ++-- bench/benchmark_cdist.py | 10 ++--- bench/benchmark_damerau_levenshtein.py | 2 + bench/benchmark_fuzz.py | 4 +- bench/benchmark_indel_levenshtein.py | 4 +- bench/benchmark_jaro.py | 4 +- bench/benchmark_jaro_winkler.py | 4 +- bench/benchmark_osa.py | 4 +- bench/benchmark_partial_ratio_long_needle.py | 6 ++- bench/benchmark_partial_ratio_short_needle.py | 6 ++- bench/benchmark_scorer.py | 10 ++--- bench/benchmark_uniform_levenshtein.py | 4 +- bench/benchmark_visualize.py | 2 +- docs/requirements.txt | 6 +-- setup.py | 3 +- src/rapidfuzz/__init__.py | 2 +- src/rapidfuzz/__init__.pyi | 12 +++-- src/rapidfuzz/cpp_common.pxd | 25 +++++------ src/rapidfuzz/distance/DamerauLevenshtein.py | 14 +++--- src/rapidfuzz/distance/DamerauLevenshtein.pyi | 6 ++- .../distance/DamerauLevenshtein_cpp.py | 14 +++--- .../distance/DamerauLevenshtein_py.pyi | 3 +- src/rapidfuzz/distance/Hamming.py | 14 +++--- src/rapidfuzz/distance/Hamming.pyi | 3 +- src/rapidfuzz/distance/Hamming_cpp.py | 16 +++---- src/rapidfuzz/distance/Hamming_py.pyi | 4 +- src/rapidfuzz/distance/Indel.py | 14 +++--- src/rapidfuzz/distance/Indel.pyi | 3 +- src/rapidfuzz/distance/Indel_cpp.py | 16 +++---- src/rapidfuzz/distance/Indel_py.py | 6 +-- src/rapidfuzz/distance/Indel_py.pyi | 6 ++- src/rapidfuzz/distance/Jaro.py | 14 +++--- src/rapidfuzz/distance/Jaro.pyi | 3 +- src/rapidfuzz/distance/JaroWinkler.py | 14 +++--- src/rapidfuzz/distance/JaroWinkler.pyi | 3 +- src/rapidfuzz/distance/JaroWinkler_cpp.py | 11 ++--- src/rapidfuzz/distance/JaroWinkler_py.py | 1 + src/rapidfuzz/distance/JaroWinkler_py.pyi | 3 +- src/rapidfuzz/distance/Jaro_cpp.py | 10 ++--- src/rapidfuzz/distance/Jaro_py.pyi | 3 +- src/rapidfuzz/distance/LCSseq.py | 14 +++--- src/rapidfuzz/distance/LCSseq.pyi | 3 +- src/rapidfuzz/distance/LCSseq_cpp.py | 16 +++---- src/rapidfuzz/distance/LCSseq_py.pyi | 6 ++- src/rapidfuzz/distance/Levenshtein.py | 14 +++--- src/rapidfuzz/distance/Levenshtein.pyi | 3 +- src/rapidfuzz/distance/Levenshtein_cpp.py | 16 +++---- src/rapidfuzz/distance/Levenshtein_py.pyi | 7 ++- src/rapidfuzz/distance/OSA.py | 14 +++--- src/rapidfuzz/distance/OSA.pyi | 3 +- src/rapidfuzz/distance/OSA_cpp.py | 12 ++--- src/rapidfuzz/distance/OSA_py.pyi | 3 +- src/rapidfuzz/distance/__init__.py | 3 +- src/rapidfuzz/distance/__init__.pyi | 18 ++++---- src/rapidfuzz/distance/_initialize_cpp.pxd | 5 ++- src/rapidfuzz/distance/_initialize_cpp.pyx | 20 +++++---- src/rapidfuzz/distance/metrics_cpp.pyi | 3 +- src/rapidfuzz/distance/metrics_cpp.pyx | 27 ++++++----- src/rapidfuzz/fuzz.pyi | 5 ++- src/rapidfuzz/fuzz_cpp.pyx | 25 ++++++----- src/rapidfuzz/fuzz_py.py | 14 +++--- src/rapidfuzz/fuzz_py.pyi | 8 ++-- src/rapidfuzz/process.pyi | 20 ++------- src/rapidfuzz/process_cpp.py | 31 ++++++------- src/rapidfuzz/process_cpp_impl.pyi | 20 ++------- src/rapidfuzz/process_cpp_impl.pyx | 45 +++++++++---------- src/rapidfuzz/process_py.py | 5 ++- src/rapidfuzz/string_metric.py | 3 +- src/rapidfuzz/string_metric.pyi | 2 +- src/rapidfuzz/utils.py | 1 - src/rapidfuzz/utils_cpp.pyx | 12 ++--- tests/distance/test_JaroWinkler.py | 2 + tests/distance/test_Levenshtein.py | 9 +--- tests/distance/test_OSA.py | 7 +-- tests/distance/test_init.py | 21 +++------ tests/test_fuzz.py | 5 ++- tests/test_hypothesis.py | 23 ++++------ tests/test_process.py | 3 +- tests/test_utils.py | 2 +- 80 files changed, 380 insertions(+), 369 deletions(-) diff --git a/.clang-format b/.clang-format index 77f35ef..fbbb227 100644 --- a/.clang-format +++ b/.clang-format @@ -5,7 +5,6 @@ AccessModifierOffset: -4 AllowShortIfStatementsOnASingleLine: true PointerAlignment: Left AllowShortBlocksOnASingleLine: Always -AllowShortIfStatementsOnASingleLine: true AllowShortFunctionsOnASingleLine: None AllowShortLambdasOnASingleLine: None BreakBeforeBraces: Custom diff --git a/_custom_build/backend.py b/_custom_build/backend.py index 70d67ad..68bdc3b 100644 --- a/_custom_build/backend.py +++ b/_custom_build/backend.py @@ -1,10 +1,11 @@ -from setuptools import build_meta as _orig +import platform as _platform +import subprocess as _subprocess + from packaging import version as _version from packaging.tags import sys_tags as _sys_tags -from skbuild.exceptions import SKBuildError as _SKBuildError +from setuptools import build_meta as _orig from skbuild.cmaker import get_cmake_version as _get_cmake_version -import subprocess as _subprocess -import platform as _platform +from skbuild.exceptions import SKBuildError as _SKBuildError prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel build_wheel = _orig.build_wheel diff --git a/bench/benchmark_cdist.py b/bench/benchmark_cdist.py index 0d58653..cebe74f 100644 --- a/bench/benchmark_cdist.py +++ b/bench/benchmark_cdist.py @@ -1,11 +1,11 @@ import importlib import random -from timeit import timeit -import numpy as np -import matplotlib.pyplot as plt -import matplotlib - import string +from timeit import timeit + +import matplotlib +import matplotlib.pyplot as plt +import numpy as np random.seed(18) diff --git a/bench/benchmark_damerau_levenshtein.py b/bench/benchmark_damerau_levenshtein.py index e69b7c0..399ee72 100644 --- a/bench/benchmark_damerau_levenshtein.py +++ b/bench/benchmark_damerau_levenshtein.py @@ -1,7 +1,9 @@ # todo combine benchmarks of scorers into common code base import timeit + import pandas + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") start = timeit.default_timer() diff --git a/bench/benchmark_fuzz.py b/bench/benchmark_fuzz.py index b8a564a..ae245ed 100644 --- a/bench/benchmark_fuzz.py +++ b/bench/benchmark_fuzz.py @@ -1,7 +1,9 @@ # todo combine benchmarks of scorers into common code base import timeit -import pandas + import numpy as np +import pandas + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") diff --git a/bench/benchmark_indel_levenshtein.py b/bench/benchmark_indel_levenshtein.py index bbfda5d..e5dea00 100644 --- a/bench/benchmark_indel_levenshtein.py +++ b/bench/benchmark_indel_levenshtein.py @@ -1,7 +1,9 @@ # todo combine benchmarks of scorers into common code base import timeit -import pandas + import numpy as np +import pandas + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") diff --git a/bench/benchmark_jaro.py b/bench/benchmark_jaro.py index de74f9c..308de4a 100644 --- a/bench/benchmark_jaro.py +++ b/bench/benchmark_jaro.py @@ -1,7 +1,9 @@ # todo combine benchmarks of scorers into common code base import timeit -import pandas + import numpy as np +import pandas + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") diff --git a/bench/benchmark_jaro_winkler.py b/bench/benchmark_jaro_winkler.py index 4a46eff..0e5b7e3 100644 --- a/bench/benchmark_jaro_winkler.py +++ b/bench/benchmark_jaro_winkler.py @@ -1,7 +1,9 @@ # todo combine benchmarks of scorers into common code base import timeit -import pandas + import numpy as np +import pandas + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") diff --git a/bench/benchmark_osa.py b/bench/benchmark_osa.py index 9b483c0..0da1c80 100644 --- a/bench/benchmark_osa.py +++ b/bench/benchmark_osa.py @@ -1,7 +1,9 @@ # todo combine benchmarks of scorers into common code base import timeit -import pandas + import numpy as np +import pandas + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") diff --git a/bench/benchmark_partial_ratio_long_needle.py b/bench/benchmark_partial_ratio_long_needle.py index 31cfff2..faace71 100644 --- a/bench/benchmark_partial_ratio_long_needle.py +++ b/bench/benchmark_partial_ratio_long_needle.py @@ -1,7 +1,9 @@ -import pandas as pd -import numpy as np import timeit +import numpy as np +import pandas as pd + + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") start = timeit.default_timer() diff --git a/bench/benchmark_partial_ratio_short_needle.py b/bench/benchmark_partial_ratio_short_needle.py index a971e45..ac7d7b0 100644 --- a/bench/benchmark_partial_ratio_short_needle.py +++ b/bench/benchmark_partial_ratio_short_needle.py @@ -1,7 +1,9 @@ -import pandas as pd -import numpy as np import timeit +import numpy as np +import pandas as pd + + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") start = timeit.default_timer() diff --git a/bench/benchmark_scorer.py b/bench/benchmark_scorer.py index 39cdd09..085df0b 100644 --- a/bench/benchmark_scorer.py +++ b/bench/benchmark_scorer.py @@ -1,11 +1,11 @@ import importlib import random -from timeit import timeit -import numpy as np -import matplotlib.pyplot as plt -import matplotlib - import string +from timeit import timeit + +import matplotlib +import matplotlib.pyplot as plt +import numpy as np random.seed(18) diff --git a/bench/benchmark_uniform_levenshtein.py b/bench/benchmark_uniform_levenshtein.py index 68bd3e3..e484a4b 100644 --- a/bench/benchmark_uniform_levenshtein.py +++ b/bench/benchmark_uniform_levenshtein.py @@ -1,6 +1,8 @@ import timeit -import pandas + import numpy as np +import pandas + def benchmark(name, func, setup, lengths, count): print(f"starting {name}") diff --git a/bench/benchmark_visualize.py b/bench/benchmark_visualize.py index 863091f..a7ffd3b 100644 --- a/bench/benchmark_visualize.py +++ b/bench/benchmark_visualize.py @@ -1,5 +1,5 @@ -import pandas as pd import matplotlib.pyplot as plt +import pandas as pd df=pd.read_csv("results/levenshtein_damerau.csv") diff --git a/docs/requirements.txt b/docs/requirements.txt index 1c5b61c..1f700f0 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,6 @@ docutils==0.18.1 -Sphinx furo -numpy -sphinxcontrib-bibtex m2r2 +numpy +Sphinx +sphinxcontrib-bibtex diff --git a/setup.py b/setup.py index de5fe34..ea28e3e 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ import os + def show_message(*lines): print("=" * 74) for line in lines: @@ -45,8 +46,8 @@ setup_args = { def run_setup(with_binary): if with_binary: - from skbuild import setup import rapidfuzz_capi + from skbuild import setup setup( **setup_args, diff --git a/src/rapidfuzz/__init__.py b/src/rapidfuzz/__init__.py index a0f0ddc..6fb54b8 100644 --- a/src/rapidfuzz/__init__.py +++ b/src/rapidfuzz/__init__.py @@ -5,4 +5,4 @@ __author__: str = "Max Bachmann" __license__: str = "MIT" __version__: str = "2.10.3" -from rapidfuzz import process, distance, fuzz, string_metric, utils +from rapidfuzz import distance, fuzz, process, string_metric, utils diff --git a/src/rapidfuzz/__init__.pyi b/src/rapidfuzz/__init__.pyi index 1acdbbc..9ca9896 100644 --- a/src/rapidfuzz/__init__.pyi +++ b/src/rapidfuzz/__init__.pyi @@ -2,10 +2,8 @@ __author__: str __license__: str __version__: str -from rapidfuzz import ( - process as process, - distance as distance, - fuzz as fuzz, - string_metric as string_metric, - utils as utils, -) +from rapidfuzz import distance as distance +from rapidfuzz import fuzz as fuzz +from rapidfuzz import process as process +from rapidfuzz import string_metric as string_metric +from rapidfuzz import utils as utils diff --git a/src/rapidfuzz/cpp_common.pxd b/src/rapidfuzz/cpp_common.pxd index ff61054..5ad74b8 100644 --- a/src/rapidfuzz/cpp_common.pxd +++ b/src/rapidfuzz/cpp_common.pxd @@ -1,24 +1,23 @@ # distutils: language=c++ # cython: language_level=3, binding=True, linetrace=True -from libc.stdint cimport uint64_t, int64_t -from libc.stdlib cimport malloc, free -from libc.stddef cimport wchar_t -from libcpp.utility cimport pair -from libcpp cimport bool -from libcpp.utility cimport move from cpython.object cimport PyObject +from cpython.pycapsule cimport (PyCapsule_GetPointer, PyCapsule_IsValid, + PyCapsule_New) +from libc.stddef cimport wchar_t +from libc.stdint cimport int64_t, uint64_t +from libc.stdlib cimport free, malloc +from libcpp cimport bool +from libcpp.utility cimport move, pair from libcpp.vector cimport vector -from cpython.pycapsule cimport PyCapsule_New, PyCapsule_IsValid, PyCapsule_GetPointer - -from rapidfuzz_capi cimport ( - RF_Scorer, RF_StringType, RF_String, RF_Kwargs, RF_KwargsInit, - SCORER_STRUCT_VERSION, - RF_ScorerFlags, RF_Preprocessor, RF_GetScorerFlags, RF_ScorerFuncInit -) +from rapidfuzz_capi cimport (SCORER_STRUCT_VERSION, RF_GetScorerFlags, + RF_Kwargs, RF_KwargsInit, RF_Preprocessor, + RF_Scorer, RF_ScorerFlags, RF_ScorerFuncInit, + RF_String, RF_StringType) from array import array + cdef extern from "rapidfuzz/details/types.hpp" namespace "rapidfuzz" nogil: cpdef enum class EditType: None = 0, diff --git a/src/rapidfuzz/distance/DamerauLevenshtein.py b/src/rapidfuzz/distance/DamerauLevenshtein.py index 67552aa..a8ae3bc 100644 --- a/src/rapidfuzz/distance/DamerauLevenshtein.py +++ b/src/rapidfuzz/distance/DamerauLevenshtein.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.DamerauLevenshtein" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/DamerauLevenshtein.pyi b/src/rapidfuzz/distance/DamerauLevenshtein.pyi index 1b85eea..c5cb5d5 100644 --- a/src/rapidfuzz/distance/DamerauLevenshtein.pyi +++ b/src/rapidfuzz/distance/DamerauLevenshtein.pyi @@ -1,7 +1,9 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict -from rapidfuzz.distance import Editops, Opcodes +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol +from rapidfuzz.distance import Editops, Opcodes + class _ScorerAttributes(Protocol): _RF_ScorerPy: Dict diff --git a/src/rapidfuzz/distance/DamerauLevenshtein_cpp.py b/src/rapidfuzz/distance/DamerauLevenshtein_cpp.py index 8f1afd5..05a75b7 100644 --- a/src/rapidfuzz/distance/DamerauLevenshtein_cpp.py +++ b/src/rapidfuzz/distance/DamerauLevenshtein_cpp.py @@ -1,9 +1,11 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - damerau_levenshtein_distance as distance, - damerau_levenshtein_similarity as similarity, - damerau_levenshtein_normalized_distance as normalized_distance, - damerau_levenshtein_normalized_similarity as normalized_similarity, -) +from rapidfuzz.distance.metrics_cpp import \ + damerau_levenshtein_distance as distance +from rapidfuzz.distance.metrics_cpp import \ + damerau_levenshtein_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ + damerau_levenshtein_normalized_similarity as normalized_similarity +from rapidfuzz.distance.metrics_cpp import \ + damerau_levenshtein_similarity as similarity diff --git a/src/rapidfuzz/distance/DamerauLevenshtein_py.pyi b/src/rapidfuzz/distance/DamerauLevenshtein_py.pyi index b494af6..b27fcd9 100644 --- a/src/rapidfuzz/distance/DamerauLevenshtein_py.pyi +++ b/src/rapidfuzz/distance/DamerauLevenshtein_py.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/Hamming.py b/src/rapidfuzz/distance/Hamming.py index f0544c5..e697a06 100644 --- a/src/rapidfuzz/distance/Hamming.py +++ b/src/rapidfuzz/distance/Hamming.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.Hamming" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/Hamming.pyi b/src/rapidfuzz/distance/Hamming.pyi index 0caa762..cf5faf3 100644 --- a/src/rapidfuzz/distance/Hamming.pyi +++ b/src/rapidfuzz/distance/Hamming.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar +from typing import Callable, Hashable, Optional, Sequence, TypeVar + from rapidfuzz.distance import Editops, Opcodes _StringType = Sequence[Hashable] diff --git a/src/rapidfuzz/distance/Hamming_cpp.py b/src/rapidfuzz/distance/Hamming_cpp.py index 18ba6c2..5bd591c 100644 --- a/src/rapidfuzz/distance/Hamming_cpp.py +++ b/src/rapidfuzz/distance/Hamming_cpp.py @@ -1,11 +1,11 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - hamming_distance as distance, - hamming_similarity as similarity, - hamming_normalized_distance as normalized_distance, - hamming_normalized_similarity as normalized_similarity, - hamming_editops as editops, - hamming_opcodes as opcodes -) +from rapidfuzz.distance.metrics_cpp import hamming_distance as distance +from rapidfuzz.distance.metrics_cpp import hamming_editops as editops +from rapidfuzz.distance.metrics_cpp import \ + hamming_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ + hamming_normalized_similarity as normalized_similarity +from rapidfuzz.distance.metrics_cpp import hamming_opcodes as opcodes +from rapidfuzz.distance.metrics_cpp import hamming_similarity as similarity diff --git a/src/rapidfuzz/distance/Hamming_py.pyi b/src/rapidfuzz/distance/Hamming_py.pyi index df6ac3f..5c04a3d 100644 --- a/src/rapidfuzz/distance/Hamming_py.pyi +++ b/src/rapidfuzz/distance/Hamming_py.pyi @@ -1,5 +1,7 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol + from rapidfuzz.distance import Editops, Opcodes class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/Indel.py b/src/rapidfuzz/distance/Indel.py index ed0dda6..07557a5 100644 --- a/src/rapidfuzz/distance/Indel.py +++ b/src/rapidfuzz/distance/Indel.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.Indel" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/Indel.pyi b/src/rapidfuzz/distance/Indel.pyi index fcc9734..2ad1f0e 100644 --- a/src/rapidfuzz/distance/Indel.pyi +++ b/src/rapidfuzz/distance/Indel.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar +from typing import Callable, Hashable, Optional, Sequence, TypeVar + from rapidfuzz.distance import Editops, Opcodes _StringType = Sequence[Hashable] diff --git a/src/rapidfuzz/distance/Indel_cpp.py b/src/rapidfuzz/distance/Indel_cpp.py index 569b41a..6fe004e 100644 --- a/src/rapidfuzz/distance/Indel_cpp.py +++ b/src/rapidfuzz/distance/Indel_cpp.py @@ -1,11 +1,11 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - indel_distance as distance, - indel_similarity as similarity, - indel_normalized_distance as normalized_distance, - indel_normalized_similarity as normalized_similarity, - indel_editops as editops, - indel_opcodes as opcodes, -) +from rapidfuzz.distance.metrics_cpp import indel_distance as distance +from rapidfuzz.distance.metrics_cpp import indel_editops as editops +from rapidfuzz.distance.metrics_cpp import \ + indel_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ + indel_normalized_similarity as normalized_similarity +from rapidfuzz.distance.metrics_cpp import indel_opcodes as opcodes +from rapidfuzz.distance.metrics_cpp import indel_similarity as similarity diff --git a/src/rapidfuzz/distance/Indel_py.py b/src/rapidfuzz/distance/Indel_py.py index 73fcac8..9eba4e2 100644 --- a/src/rapidfuzz/distance/Indel_py.py +++ b/src/rapidfuzz/distance/Indel_py.py @@ -1,10 +1,8 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from .LCSseq_py import ( - similarity as lcs_seq_similarity, - _block_similarity as lcs_seq_block_similarity, -) +from .LCSseq_py import _block_similarity as lcs_seq_block_similarity +from .LCSseq_py import similarity as lcs_seq_similarity def distance(s1, s2, *, processor=None, score_cutoff=None): diff --git a/src/rapidfuzz/distance/Indel_py.pyi b/src/rapidfuzz/distance/Indel_py.pyi index 2cd760e..e64381b 100644 --- a/src/rapidfuzz/distance/Indel_py.pyi +++ b/src/rapidfuzz/distance/Indel_py.pyi @@ -1,7 +1,9 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict -from rapidfuzz.distance import Editops, Opcodes +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol +from rapidfuzz.distance import Editops, Opcodes + class _ScorerAttributes(Protocol): _RF_ScorerPy: Dict diff --git a/src/rapidfuzz/distance/Jaro.py b/src/rapidfuzz/distance/Jaro.py index a24dd6d..a04a883 100644 --- a/src/rapidfuzz/distance/Jaro.py +++ b/src/rapidfuzz/distance/Jaro.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.Jaro" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/Jaro.pyi b/src/rapidfuzz/distance/Jaro.pyi index 6dc23a3..b4243b2 100644 --- a/src/rapidfuzz/distance/Jaro.pyi +++ b/src/rapidfuzz/distance/Jaro.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/JaroWinkler.py b/src/rapidfuzz/distance/JaroWinkler.py index 9108827..f89d699 100644 --- a/src/rapidfuzz/distance/JaroWinkler.py +++ b/src/rapidfuzz/distance/JaroWinkler.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.JaroWinkler" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/JaroWinkler.pyi b/src/rapidfuzz/distance/JaroWinkler.pyi index 14c71dc..b09539b 100644 --- a/src/rapidfuzz/distance/JaroWinkler.pyi +++ b/src/rapidfuzz/distance/JaroWinkler.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/JaroWinkler_cpp.py b/src/rapidfuzz/distance/JaroWinkler_cpp.py index d78c992..aa3109c 100644 --- a/src/rapidfuzz/distance/JaroWinkler_cpp.py +++ b/src/rapidfuzz/distance/JaroWinkler_cpp.py @@ -1,9 +1,10 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - jaro_winkler_distance as distance, - jaro_winkler_similarity as similarity, - jaro_winkler_normalized_distance as normalized_distance, +from rapidfuzz.distance.metrics_cpp import jaro_winkler_distance as distance +from rapidfuzz.distance.metrics_cpp import \ + jaro_winkler_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ jaro_winkler_normalized_similarity as normalized_similarity -) +from rapidfuzz.distance.metrics_cpp import \ + jaro_winkler_similarity as similarity diff --git a/src/rapidfuzz/distance/JaroWinkler_py.py b/src/rapidfuzz/distance/JaroWinkler_py.py index d0d7036..6254d56 100644 --- a/src/rapidfuzz/distance/JaroWinkler_py.py +++ b/src/rapidfuzz/distance/JaroWinkler_py.py @@ -3,6 +3,7 @@ from rapidfuzz.distance import Jaro + def similarity(s1, s2, *, prefix_weight=0.1, processor=None, score_cutoff=None) -> float: """ Calculates the jaro winkler similarity diff --git a/src/rapidfuzz/distance/JaroWinkler_py.pyi b/src/rapidfuzz/distance/JaroWinkler_py.pyi index 14c71dc..b09539b 100644 --- a/src/rapidfuzz/distance/JaroWinkler_py.pyi +++ b/src/rapidfuzz/distance/JaroWinkler_py.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/Jaro_cpp.py b/src/rapidfuzz/distance/Jaro_cpp.py index 75bb3d0..8af5971 100644 --- a/src/rapidfuzz/distance/Jaro_cpp.py +++ b/src/rapidfuzz/distance/Jaro_cpp.py @@ -1,9 +1,9 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - jaro_distance as distance, - jaro_similarity as similarity, - jaro_normalized_distance as normalized_distance, +from rapidfuzz.distance.metrics_cpp import jaro_distance as distance +from rapidfuzz.distance.metrics_cpp import \ + jaro_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ jaro_normalized_similarity as normalized_similarity -) +from rapidfuzz.distance.metrics_cpp import jaro_similarity as similarity diff --git a/src/rapidfuzz/distance/Jaro_py.pyi b/src/rapidfuzz/distance/Jaro_py.pyi index 6dc23a3..b4243b2 100644 --- a/src/rapidfuzz/distance/Jaro_py.pyi +++ b/src/rapidfuzz/distance/Jaro_py.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/LCSseq.py b/src/rapidfuzz/distance/LCSseq.py index 0f598c6..c5f0be8 100644 --- a/src/rapidfuzz/distance/LCSseq.py +++ b/src/rapidfuzz/distance/LCSseq.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.LCSseq" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/LCSseq.pyi b/src/rapidfuzz/distance/LCSseq.pyi index fcc9734..2ad1f0e 100644 --- a/src/rapidfuzz/distance/LCSseq.pyi +++ b/src/rapidfuzz/distance/LCSseq.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar +from typing import Callable, Hashable, Optional, Sequence, TypeVar + from rapidfuzz.distance import Editops, Opcodes _StringType = Sequence[Hashable] diff --git a/src/rapidfuzz/distance/LCSseq_cpp.py b/src/rapidfuzz/distance/LCSseq_cpp.py index dd68292..7b517aa 100644 --- a/src/rapidfuzz/distance/LCSseq_cpp.py +++ b/src/rapidfuzz/distance/LCSseq_cpp.py @@ -1,11 +1,11 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - lcs_seq_distance as distance, - lcs_seq_similarity as similarity, - lcs_seq_normalized_distance as normalized_distance, - lcs_seq_normalized_similarity as normalized_similarity, - lcs_seq_editops as editops, - lcs_seq_opcodes as opcodes, -) +from rapidfuzz.distance.metrics_cpp import lcs_seq_distance as distance +from rapidfuzz.distance.metrics_cpp import lcs_seq_editops as editops +from rapidfuzz.distance.metrics_cpp import \ + lcs_seq_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ + lcs_seq_normalized_similarity as normalized_similarity +from rapidfuzz.distance.metrics_cpp import lcs_seq_opcodes as opcodes +from rapidfuzz.distance.metrics_cpp import lcs_seq_similarity as similarity diff --git a/src/rapidfuzz/distance/LCSseq_py.pyi b/src/rapidfuzz/distance/LCSseq_py.pyi index 8eb0c00..79630be 100644 --- a/src/rapidfuzz/distance/LCSseq_py.pyi +++ b/src/rapidfuzz/distance/LCSseq_py.pyi @@ -1,7 +1,9 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict -from rapidfuzz.distance import Editops, Opcodes +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol +from rapidfuzz.distance import Editops, Opcodes + class _ScorerAttributes(Protocol): _RF_ScorerPy7: Dict diff --git a/src/rapidfuzz/distance/Levenshtein.py b/src/rapidfuzz/distance/Levenshtein.py index acb9fed..69438c3 100644 --- a/src/rapidfuzz/distance/Levenshtein.py +++ b/src/rapidfuzz/distance/Levenshtein.py @@ -7,13 +7,13 @@ It's defined as the minimum number of insertions, deletions or substitutions required to transform s1 into s2. """ -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.Levenshtein" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/Levenshtein.pyi b/src/rapidfuzz/distance/Levenshtein.pyi index d83323e..bb8c15d 100644 --- a/src/rapidfuzz/distance/Levenshtein.pyi +++ b/src/rapidfuzz/distance/Levenshtein.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Tuple +from typing import Callable, Hashable, Optional, Sequence, Tuple, TypeVar + from rapidfuzz.distance import Editops, Opcodes _StringType = Sequence[Hashable] diff --git a/src/rapidfuzz/distance/Levenshtein_cpp.py b/src/rapidfuzz/distance/Levenshtein_cpp.py index 4e5d2e4..16be601 100644 --- a/src/rapidfuzz/distance/Levenshtein_cpp.py +++ b/src/rapidfuzz/distance/Levenshtein_cpp.py @@ -1,11 +1,11 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - levenshtein_distance as distance, - levenshtein_similarity as similarity, - levenshtein_normalized_distance as normalized_distance, - levenshtein_normalized_similarity as normalized_similarity, - levenshtein_editops as editops, - levenshtein_opcodes as opcodes, -) +from rapidfuzz.distance.metrics_cpp import levenshtein_distance as distance +from rapidfuzz.distance.metrics_cpp import levenshtein_editops as editops +from rapidfuzz.distance.metrics_cpp import \ + levenshtein_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ + levenshtein_normalized_similarity as normalized_similarity +from rapidfuzz.distance.metrics_cpp import levenshtein_opcodes as opcodes +from rapidfuzz.distance.metrics_cpp import levenshtein_similarity as similarity diff --git a/src/rapidfuzz/distance/Levenshtein_py.pyi b/src/rapidfuzz/distance/Levenshtein_py.pyi index f627a69..c53dbb0 100644 --- a/src/rapidfuzz/distance/Levenshtein_py.pyi +++ b/src/rapidfuzz/distance/Levenshtein_py.pyi @@ -1,7 +1,10 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Tuple, Any, Dict -from rapidfuzz.distance import Editops, Opcodes +from typing import (Any, Callable, Dict, Hashable, Optional, Sequence, Tuple, + TypeVar) + from typing_extensions import Protocol +from rapidfuzz.distance import Editops, Opcodes + class _ScorerAttributes(Protocol): _RF_ScorerPy: Dict diff --git a/src/rapidfuzz/distance/OSA.py b/src/rapidfuzz/distance/OSA.py index fb33a37..5effc8d 100644 --- a/src/rapidfuzz/distance/OSA.py +++ b/src/rapidfuzz/distance/OSA.py @@ -1,13 +1,13 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz._utils import ( - fallback_import as _fallback_import, - default_distance_attribute as _dist_attr, - default_similarity_attribute as _sim_attr, - default_normalized_distance_attribute as _norm_dist_attr, - default_normalized_similarity_attribute as _norm_sim_attr, -) +from rapidfuzz._utils import default_distance_attribute as _dist_attr +from rapidfuzz._utils import \ + default_normalized_distance_attribute as _norm_dist_attr +from rapidfuzz._utils import \ + default_normalized_similarity_attribute as _norm_sim_attr +from rapidfuzz._utils import default_similarity_attribute as _sim_attr +from rapidfuzz._utils import fallback_import as _fallback_import _mod = "rapidfuzz.distance.OSA" distance = _fallback_import(_mod, "distance") diff --git a/src/rapidfuzz/distance/OSA.pyi b/src/rapidfuzz/distance/OSA.pyi index b494af6..b27fcd9 100644 --- a/src/rapidfuzz/distance/OSA.pyi +++ b/src/rapidfuzz/distance/OSA.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/OSA_cpp.py b/src/rapidfuzz/distance/OSA_cpp.py index 9f963a4..f81df88 100644 --- a/src/rapidfuzz/distance/OSA_cpp.py +++ b/src/rapidfuzz/distance/OSA_cpp.py @@ -1,9 +1,9 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance.metrics_cpp import ( - osa_distance as distance, - osa_similarity as similarity, - osa_normalized_distance as normalized_distance, - osa_normalized_similarity as normalized_similarity, -) +from rapidfuzz.distance.metrics_cpp import osa_distance as distance +from rapidfuzz.distance.metrics_cpp import \ + osa_normalized_distance as normalized_distance +from rapidfuzz.distance.metrics_cpp import \ + osa_normalized_similarity as normalized_similarity +from rapidfuzz.distance.metrics_cpp import osa_similarity as similarity diff --git a/src/rapidfuzz/distance/OSA_py.pyi b/src/rapidfuzz/distance/OSA_py.pyi index b494af6..b27fcd9 100644 --- a/src/rapidfuzz/distance/OSA_py.pyi +++ b/src/rapidfuzz/distance/OSA_py.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol class _ScorerAttributes(Protocol): diff --git a/src/rapidfuzz/distance/__init__.py b/src/rapidfuzz/distance/__init__.py index 0bb2066..8b87cd5 100644 --- a/src/rapidfuzz/distance/__init__.py +++ b/src/rapidfuzz/distance/__init__.py @@ -11,4 +11,5 @@ Opcodes = _fallback_import(_mod, "Opcodes", False) ScoreAlignment = _fallback_import(_mod, "ScoreAlignment", False) MatchingBlock = _fallback_import(_mod, "MatchingBlock", False) -from . import Hamming, Indel, Jaro, JaroWinkler, Levenshtein, LCSseq, DamerauLevenshtein +from . import (DamerauLevenshtein, Hamming, Indel, Jaro, JaroWinkler, LCSseq, + Levenshtein) diff --git a/src/rapidfuzz/distance/__init__.pyi b/src/rapidfuzz/distance/__init__.pyi index 08645b3..fae164d 100644 --- a/src/rapidfuzz/distance/__init__.pyi +++ b/src/rapidfuzz/distance/__init__.pyi @@ -1,14 +1,12 @@ -from typing import Tuple, List, Union +from typing import List, Tuple, Union -from . import ( - Hamming as Hamming, - Indel as Indel, - Jaro as Jaro, - JaroWinkler as JaroWinkler, - Levenshtein as Levenshtein, - LCSseq as LCSseq, - DamerauLevenshtein as DamerauLevenshtein, -) +from . import DamerauLevenshtein as DamerauLevenshtein +from . import Hamming as Hamming +from . import Indel as Indel +from . import Jaro as Jaro +from . import JaroWinkler as JaroWinkler +from . import LCSseq as LCSseq +from . import Levenshtein as Levenshtein _AnyOpList = Union[ List[Union[Editop, Tuple[str, int, int]]], diff --git a/src/rapidfuzz/distance/_initialize_cpp.pxd b/src/rapidfuzz/distance/_initialize_cpp.pxd index 024b99c..38ca75c 100644 --- a/src/rapidfuzz/distance/_initialize_cpp.pxd +++ b/src/rapidfuzz/distance/_initialize_cpp.pxd @@ -1,9 +1,10 @@ # distutils: language=c++ # cython: language_level=3, binding=True, linetrace=True -from libcpp.vector cimport vector -from libcpp cimport bool from cpp_common cimport RfEditops, RfOpcodes +from libcpp cimport bool +from libcpp.vector cimport vector + cdef class Editops: cdef RfEditops editops diff --git a/src/rapidfuzz/distance/_initialize_cpp.pyx b/src/rapidfuzz/distance/_initialize_cpp.pyx index d50f774..de0cb35 100644 --- a/src/rapidfuzz/distance/_initialize_cpp.pyx +++ b/src/rapidfuzz/distance/_initialize_cpp.pyx @@ -1,17 +1,19 @@ # distutils: language=c++ # cython: language_level=3, binding=True, linetrace=True -from rapidfuzz_capi cimport RF_String -from cpp_common cimport RfEditOp, RfOpcode, EditType, is_valid_string, convert_string - -from libcpp cimport bool -from libcpp.vector cimport vector -from libcpp.utility cimport move -from libc.stdlib cimport malloc, free -from libc.stdint cimport uint32_t, int64_t +from cpp_common cimport (EditType, RfEditOp, RfOpcode, convert_string, + is_valid_string) from cpython.list cimport PyList_New, PyList_SET_ITEM +from cpython.pycapsule cimport (PyCapsule_GetPointer, PyCapsule_IsValid, + PyCapsule_New) from cpython.ref cimport Py_INCREF -from cpython.pycapsule cimport PyCapsule_New, PyCapsule_IsValid, PyCapsule_GetPointer +from libc.stdint cimport int64_t, uint32_t +from libc.stdlib cimport free, malloc +from libcpp cimport bool +from libcpp.utility cimport move +from libcpp.vector cimport vector +from rapidfuzz_capi cimport RF_String + cdef extern from "rapidfuzz/details/types.hpp" namespace "rapidfuzz" nogil: cdef struct LevenshteinWeightTable: diff --git a/src/rapidfuzz/distance/metrics_cpp.pyi b/src/rapidfuzz/distance/metrics_cpp.pyi index b232e5e..7a90448 100644 --- a/src/rapidfuzz/distance/metrics_cpp.pyi +++ b/src/rapidfuzz/distance/metrics_cpp.pyi @@ -1,4 +1,5 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Tuple +from typing import Callable, Hashable, Optional, Sequence, Tuple, TypeVar + from rapidfuzz.distance import Editops, Opcodes _StringType = Sequence[Hashable] diff --git a/src/rapidfuzz/distance/metrics_cpp.pyx b/src/rapidfuzz/distance/metrics_cpp.pyx index 47abcfc..5b782a5 100644 --- a/src/rapidfuzz/distance/metrics_cpp.pyx +++ b/src/rapidfuzz/distance/metrics_cpp.pyx @@ -2,21 +2,28 @@ # cython: language_level=3, binding=True, linetrace=True from ._initialize_cpp import Editops + +from rapidfuzz_capi cimport (RF_SCORER_FLAG_MULTI_STRING_CALL, + RF_SCORER_FLAG_MULTI_STRING_INIT, + RF_SCORER_FLAG_RESULT_F64, + RF_SCORER_FLAG_RESULT_I64, + RF_SCORER_FLAG_SYMMETRIC, RF_Kwargs, + RF_Preprocess, RF_Scorer, RF_ScorerFlags, + RF_ScorerFunc, RF_String) + from ._initialize_cpp cimport Editops, RfEditops -from rapidfuzz_capi cimport ( - RF_String, RF_Scorer, RF_Kwargs, RF_ScorerFunc, RF_Preprocess, RF_ScorerFlags, - RF_SCORER_FLAG_RESULT_F64, RF_SCORER_FLAG_RESULT_I64, RF_SCORER_FLAG_SYMMETRIC, - RF_SCORER_FLAG_MULTI_STRING_INIT, RF_SCORER_FLAG_MULTI_STRING_CALL -) # required for preprocess_strings -from array import array -from cpp_common cimport RF_StringWrapper, preprocess_strings, NoKwargsInit, CreateScorerContext -from libcpp cimport bool -from libc.stdlib cimport malloc, free -from libc.stdint cimport INT64_MAX, int64_t +from array import array + +from cpp_common cimport (CreateScorerContext, NoKwargsInit, RF_StringWrapper, + preprocess_strings) from cpython.pycapsule cimport PyCapsule_New +from libc.stdint cimport INT64_MAX, int64_t +from libc.stdlib cimport free, malloc +from libcpp cimport bool + cdef extern from "rapidfuzz/details/types.hpp" namespace "rapidfuzz" nogil: cdef struct LevenshteinWeightTable: diff --git a/src/rapidfuzz/fuzz.pyi b/src/rapidfuzz/fuzz.pyi index 8c477e2..9951fec 100644 --- a/src/rapidfuzz/fuzz.pyi +++ b/src/rapidfuzz/fuzz.pyi @@ -1,6 +1,7 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar -from rapidfuzz.utils import default_process +from typing import Callable, Hashable, Optional, Sequence, TypeVar + from rapidfuzz.distance import ScoreAlignment +from rapidfuzz.utils import default_process _StringType = Sequence[Hashable] _S1 = TypeVar("_S1") diff --git a/src/rapidfuzz/fuzz_cpp.pyx b/src/rapidfuzz/fuzz_cpp.pyx index 36b9349..1b9fbdc 100644 --- a/src/rapidfuzz/fuzz_cpp.pyx +++ b/src/rapidfuzz/fuzz_cpp.pyx @@ -3,25 +3,26 @@ from .distance._initialize_cpp import ScoreAlignment -from rapidfuzz_capi cimport ( - RF_String, RF_Scorer, RF_ScorerFunc, RF_Kwargs, RF_ScorerFlags, - RF_SCORER_FLAG_RESULT_F64, RF_SCORER_FLAG_SYMMETRIC, - RF_SCORER_FLAG_MULTI_STRING_INIT -) +from rapidfuzz_capi cimport (RF_SCORER_FLAG_MULTI_STRING_INIT, + RF_SCORER_FLAG_RESULT_F64, + RF_SCORER_FLAG_SYMMETRIC, RF_Kwargs, RF_Scorer, + RF_ScorerFlags, RF_ScorerFunc, RF_String) # required for preprocess_strings -from rapidfuzz.utils import default_process -from array import array -from cpp_common cimport ( - RF_StringWrapper, preprocess_strings, RfScoreAlignment, NoKwargsInit, - CreateScorerContext, CreateScorerContextPy, AddScorerContext -) -from libc.stdint cimport uint32_t, int64_t +from array import array + +from rapidfuzz.utils import default_process + +from cpp_common cimport (AddScorerContext, CreateScorerContext, + CreateScorerContextPy, NoKwargsInit, RF_StringWrapper, + RfScoreAlignment, preprocess_strings) +from libc.stdint cimport int64_t, uint32_t from libcpp cimport bool from array import array + cdef extern from "fuzz_cpp.hpp": double ratio_func( const RF_String&, const RF_String&, double) nogil except + double partial_ratio_func( const RF_String&, const RF_String&, double) nogil except + diff --git a/src/rapidfuzz/fuzz_py.py b/src/rapidfuzz/fuzz_py.py index 135d38e..f815ec5 100644 --- a/src/rapidfuzz/fuzz_py.py +++ b/src/rapidfuzz/fuzz_py.py @@ -1,12 +1,14 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.utils_py import default_process -from rapidfuzz.distance.Indel_py import ( - normalized_similarity as indel_normalized_similarity, - _block_normalized_similarity as indel_block_normalized_similarity, - distance as indel_distance, -) from math import ceil + +from rapidfuzz.distance.Indel_py import \ + _block_normalized_similarity as indel_block_normalized_similarity +from rapidfuzz.distance.Indel_py import distance as indel_distance +from rapidfuzz.distance.Indel_py import \ + normalized_similarity as indel_normalized_similarity +from rapidfuzz.utils_py import default_process + from .distance._initialize_py import ScoreAlignment diff --git a/src/rapidfuzz/fuzz_py.pyi b/src/rapidfuzz/fuzz_py.pyi index de5ef85..633b3cf 100644 --- a/src/rapidfuzz/fuzz_py.pyi +++ b/src/rapidfuzz/fuzz_py.pyi @@ -1,8 +1,10 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Any, Dict -from rapidfuzz.utils import default_process -from rapidfuzz.distance import ScoreAlignment +from typing import Any, Callable, Dict, Hashable, Optional, Sequence, TypeVar + from typing_extensions import Protocol +from rapidfuzz.distance import ScoreAlignment +from rapidfuzz.utils import default_process + class _ScorerAttributes(Protocol): _RF_ScorerPy: Dict diff --git a/src/rapidfuzz/process.pyi b/src/rapidfuzz/process.pyi index 84cde6e..9e63a40 100644 --- a/src/rapidfuzz/process.pyi +++ b/src/rapidfuzz/process.pyi @@ -1,19 +1,7 @@ -from typing import ( - Any, - Collection, - Mapping, - Tuple, - Callable, - Hashable, - Sequence, - Iterable, - Optional, - Union, - overload, - TypeVar, - List, - Generator, -) +from typing import (Any, Callable, Collection, Generator, Hashable, Iterable, + List, Mapping, Optional, Sequence, Tuple, TypeVar, Union, + overload) + from rapidfuzz.fuzz import WRatio, ratio _StringType = Sequence[Hashable] diff --git a/src/rapidfuzz/process_cpp.py b/src/rapidfuzz/process_cpp.py index d0c89df..4b48485 100644 --- a/src/rapidfuzz/process_cpp.py +++ b/src/rapidfuzz/process_cpp.py @@ -1,23 +1,20 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.process_cpp_impl import ( - FLOAT32 as _FLOAT32, - FLOAT64 as _FLOAT64, - INT8 as _INT8, - INT16 as _INT16, - INT32 as _INT32, - INT64 as _INT64, - UINT8 as _UINT8, - UINT16 as _UINT16, - UINT32 as _UINT32, - UINT64 as _UINT64, - cdist as _cdist, - extract as extract, - extractOne as extractOne, - extract_iter as extract_iter, -) - from rapidfuzz.fuzz import ratio as _ratio +from rapidfuzz.process_cpp_impl import FLOAT32 as _FLOAT32 +from rapidfuzz.process_cpp_impl import FLOAT64 as _FLOAT64 +from rapidfuzz.process_cpp_impl import INT8 as _INT8 +from rapidfuzz.process_cpp_impl import INT16 as _INT16 +from rapidfuzz.process_cpp_impl import INT32 as _INT32 +from rapidfuzz.process_cpp_impl import INT64 as _INT64 +from rapidfuzz.process_cpp_impl import UINT8 as _UINT8 +from rapidfuzz.process_cpp_impl import UINT16 as _UINT16 +from rapidfuzz.process_cpp_impl import UINT32 as _UINT32 +from rapidfuzz.process_cpp_impl import UINT64 as _UINT64 +from rapidfuzz.process_cpp_impl import cdist as _cdist +from rapidfuzz.process_cpp_impl import extract as extract +from rapidfuzz.process_cpp_impl import extract_iter as extract_iter +from rapidfuzz.process_cpp_impl import extractOne as extractOne def _dtype_to_type_num(dtype): diff --git a/src/rapidfuzz/process_cpp_impl.pyi b/src/rapidfuzz/process_cpp_impl.pyi index 174d0f5..3f65a92 100644 --- a/src/rapidfuzz/process_cpp_impl.pyi +++ b/src/rapidfuzz/process_cpp_impl.pyi @@ -1,19 +1,7 @@ -from typing import ( - Any, - Collection, - Mapping, - Tuple, - Callable, - Hashable, - Sequence, - Iterable, - Optional, - Union, - overload, - TypeVar, - List, - Generator, -) +from typing import (Any, Callable, Collection, Generator, Hashable, Iterable, + List, Mapping, Optional, Sequence, Tuple, TypeVar, Union, + overload) + from rapidfuzz.fuzz import WRatio, ratio _StringType = Sequence[Hashable] diff --git a/src/rapidfuzz/process_cpp_impl.pyx b/src/rapidfuzz/process_cpp_impl.pyx index 9207910..c7982af 100644 --- a/src/rapidfuzz/process_cpp_impl.pyx +++ b/src/rapidfuzz/process_cpp_impl.pyx @@ -1,39 +1,35 @@ # distutils: language=c++ # cython: language_level=3, binding=True, linetrace=True -from rapidfuzz.utils import default_process from rapidfuzz.fuzz import WRatio, ratio +from rapidfuzz.utils import default_process -from libcpp cimport bool -from libcpp.vector cimport vector -from libcpp cimport algorithm -from libcpp.utility cimport move -from libc.stdint cimport uint8_t, int32_t, uint64_t, int64_t -from libc.math cimport floor - -from cpython.list cimport PyList_New, PyList_SET_ITEM -from cpython.ref cimport Py_INCREF cimport cython -from cpython.exc cimport PyErr_CheckSignals +from cpp_common cimport (PyObjectWrapper, RF_KwargsWrapper, RF_StringWrapper, + conv_sequence, get_score_cutoff_f64, + get_score_cutoff_i64) from cpython cimport Py_buffer -from cpython.buffer cimport PyBUF_ND, PyBUF_SIMPLE, PyBUF_F_CONTIGUOUS +from cpython.buffer cimport PyBUF_F_CONTIGUOUS, PyBUF_ND, PyBUF_SIMPLE +from cpython.exc cimport PyErr_CheckSignals +from cpython.list cimport PyList_New, PyList_SET_ITEM from cpython.object cimport PyObject - -from cpp_common cimport ( - PyObjectWrapper, RF_StringWrapper, RF_KwargsWrapper, - conv_sequence, get_score_cutoff_f64, get_score_cutoff_i64 -) +from cpython.ref cimport Py_INCREF +from libc.math cimport floor +from libc.stdint cimport int32_t, int64_t, uint8_t, uint64_t +from libcpp cimport algorithm, bool +from libcpp.utility cimport move +from libcpp.vector cimport vector import heapq from array import array -from rapidfuzz_capi cimport ( - RF_Preprocess, RF_Kwargs, RF_String, RF_Scorer, RF_ScorerFunc, - RF_Preprocessor, RF_ScorerFlags, - RF_SCORER_FLAG_RESULT_F64, RF_SCORER_FLAG_RESULT_I64, - RF_SCORER_FLAG_SYMMETRIC -) -from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer +from cpython.pycapsule cimport PyCapsule_GetPointer, PyCapsule_IsValid +from rapidfuzz_capi cimport (RF_SCORER_FLAG_RESULT_F64, + RF_SCORER_FLAG_RESULT_I64, + RF_SCORER_FLAG_SYMMETRIC, RF_Kwargs, + RF_Preprocess, RF_Preprocessor, RF_Scorer, + RF_ScorerFlags, RF_ScorerFunc, RF_String) + cdef extern from "process_cpp.hpp": cdef cppclass ExtractComp: @@ -1225,6 +1221,7 @@ cdef inline MatrixType dtype_to_type_num_i64(dtype) except MatrixType.UNDEFINED: from cpython cimport Py_buffer from libcpp.vector cimport vector + cdef class Matrix: cdef Py_ssize_t shape[2] cdef Py_ssize_t strides[2] diff --git a/src/rapidfuzz/process_py.py b/src/rapidfuzz/process_py.py index 063aabe..e527b6c 100644 --- a/src/rapidfuzz/process_py.py +++ b/src/rapidfuzz/process_py.py @@ -1,10 +1,11 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.utils import default_process -from rapidfuzz.fuzz import WRatio, ratio import heapq +from rapidfuzz.fuzz import WRatio, ratio +from rapidfuzz.utils import default_process + def _get_scorer_flags_py(scorer, kwargs): params = getattr(scorer, "_RF_ScorerPy", None) diff --git a/src/rapidfuzz/string_metric.py b/src/rapidfuzz/string_metric.py index bc0a985..36fbca2 100644 --- a/src/rapidfuzz/string_metric.py +++ b/src/rapidfuzz/string_metric.py @@ -1,9 +1,10 @@ # SPDX-License-Identifier: MIT # Copyright (C) 2022 Max Bachmann -from rapidfuzz.distance import Levenshtein, Hamming, Jaro, JaroWinkler import warnings +from rapidfuzz.distance import Hamming, Jaro, JaroWinkler, Levenshtein + def levenshtein( s1, s2, *, weights=(1, 1, 1), processor=None, max=None, score_cutoff=None diff --git a/src/rapidfuzz/string_metric.pyi b/src/rapidfuzz/string_metric.pyi index 2ff83b6..0c028c6 100644 --- a/src/rapidfuzz/string_metric.pyi +++ b/src/rapidfuzz/string_metric.pyi @@ -1,4 +1,4 @@ -from typing import Callable, Hashable, Sequence, Optional, TypeVar, Tuple, List +from typing import Callable, Hashable, List, Optional, Sequence, Tuple, TypeVar _StringType = Sequence[Hashable] _S1 = TypeVar("_S1") diff --git a/src/rapidfuzz/utils.py b/src/rapidfuzz/utils.py index 5535d50..a9b06a8 100644 --- a/src/rapidfuzz/utils.py +++ b/src/rapidfuzz/utils.py @@ -3,5 +3,4 @@ from rapidfuzz._utils import fallback_import as _fallback_import - default_process = _fallback_import("rapidfuzz.utils", "default_process") diff --git a/src/rapidfuzz/utils_cpp.pyx b/src/rapidfuzz/utils_cpp.pyx index 37578c2..6c64626 100644 --- a/src/rapidfuzz/utils_cpp.pyx +++ b/src/rapidfuzz/utils_cpp.pyx @@ -1,16 +1,16 @@ # distutils: language=c++ # cython: language_level=3, binding=True, linetrace=True -from rapidfuzz_capi cimport RF_String, PREPROCESSOR_STRUCT_VERSION, RF_Preprocessor -from cpp_common cimport ( - is_valid_string, convert_string, hash_array, hash_sequence, - conv_sequence -) - +from cpp_common cimport (conv_sequence, convert_string, hash_array, + hash_sequence, is_valid_string) from cpython.pycapsule cimport PyCapsule_New from libcpp cimport bool +from rapidfuzz_capi cimport (PREPROCESSOR_STRUCT_VERSION, RF_Preprocessor, + RF_String) + from array import array + cdef extern from "utils_cpp.hpp": object default_process_impl(object) nogil except + void validate_string(object py_str, const char* err) except + diff --git a/tests/distance/test_JaroWinkler.py b/tests/distance/test_JaroWinkler.py index 73bbba8..907a88f 100644 --- a/tests/distance/test_JaroWinkler.py +++ b/tests/distance/test_JaroWinkler.py @@ -2,10 +2,12 @@ # -*- coding: utf-8 -*- import unittest + import pytest from rapidfuzz.distance import JaroWinkler_cpp, JaroWinkler_py + def isclose(a, b, rel_tol=1e-09, abs_tol=0.0): return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol) diff --git a/tests/distance/test_Levenshtein.py b/tests/distance/test_Levenshtein.py index 919fa4b..b35aab8 100644 --- a/tests/distance/test_Levenshtein.py +++ b/tests/distance/test_Levenshtein.py @@ -4,13 +4,8 @@ import unittest from rapidfuzz import process -from rapidfuzz.distance import ( - Opcodes, - Opcode, - Levenshtein_cpp, - Levenshtein_py, - Levenshtein as _Levenshtein, -) +from rapidfuzz.distance import Levenshtein as _Levenshtein +from rapidfuzz.distance import Levenshtein_cpp, Levenshtein_py, Opcode, Opcodes Levenshtein_cpp.distance._RF_ScorerPy = _Levenshtein.distance._RF_ScorerPy Levenshtein_cpp.normalized_distance._RF_ScorerPy = ( diff --git a/tests/distance/test_OSA.py b/tests/distance/test_OSA.py index 3195a85..5923287 100644 --- a/tests/distance/test_OSA.py +++ b/tests/distance/test_OSA.py @@ -4,11 +4,8 @@ import unittest from rapidfuzz import process -from rapidfuzz.distance import ( - OSA_cpp, - OSA_py, - OSA as _OSA, -) +from rapidfuzz.distance import OSA as _OSA +from rapidfuzz.distance import OSA_cpp, OSA_py OSA_cpp.distance._RF_ScorerPy = _OSA.distance._RF_ScorerPy OSA_cpp.normalized_distance._RF_ScorerPy = ( diff --git a/tests/distance/test_init.py b/tests/distance/test_init.py index d5b9cce..96e2dde 100644 --- a/tests/distance/test_init.py +++ b/tests/distance/test_init.py @@ -1,22 +1,15 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import unittest -import pytest - -from hypothesis import given, settings -import hypothesis.strategies as st - import random +import unittest -from rapidfuzz.distance import ( - Levenshtein, - Editops, - Opcodes, - Editop, - Opcode, - MatchingBlock, -) +import hypothesis.strategies as st +import pytest +from hypothesis import given, settings + +from rapidfuzz.distance import (Editop, Editops, Levenshtein, MatchingBlock, + Opcode, Opcodes) def test_editops_comparision(): diff --git a/tests/test_fuzz.py b/tests/test_fuzz.py index b76cad0..a00cc97 100644 --- a/tests/test_fuzz.py +++ b/tests/test_fuzz.py @@ -2,10 +2,11 @@ # -*- coding: utf-8 -*- import unittest -import pytest from array import array -from rapidfuzz import fuzz_py, fuzz_cpp, utils +import pytest + +from rapidfuzz import fuzz_cpp, fuzz_py, utils from rapidfuzz.distance import ScoreAlignment diff --git a/tests/test_hypothesis.py b/tests/test_hypothesis.py index 466d6b5..1937d55 100644 --- a/tests/test_hypothesis.py +++ b/tests/test_hypothesis.py @@ -1,24 +1,19 @@ -from itertools import product +import random from functools import partial +from itertools import product from string import ascii_letters, digits, punctuation -from hypothesis import given, assume, settings import hypothesis.strategies as st +import numpy as np import pytest +from hypothesis import assume, given, settings from rapidfuzz import fuzz, process, utils -from rapidfuzz.distance import ( - Levenshtein_cpp, - Levenshtein_py, - Levenshtein as _Levenshtein, - Indel_cpp, - Indel_py, - Indel as _Indel, - JaroWinkler_py, - JaroWinkler_cpp, -) -import random -import numpy as np +from rapidfuzz.distance import Indel as _Indel +from rapidfuzz.distance import (Indel_cpp, Indel_py, JaroWinkler_cpp, + JaroWinkler_py) +from rapidfuzz.distance import Levenshtein as _Levenshtein +from rapidfuzz.distance import Levenshtein_cpp, Levenshtein_py Levenshtein_cpp.distance._RF_ScorerPy = _Levenshtein.distance._RF_ScorerPy Levenshtein_cpp.normalized_distance._RF_ScorerPy = ( diff --git a/tests/test_process.py b/tests/test_process.py index b786d2d..7693a4e 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -2,9 +2,10 @@ # -*- coding: utf-8 -*- import unittest + import pytest -from rapidfuzz import process_py, process_cpp, fuzz +from rapidfuzz import fuzz, process_cpp, process_py class process: diff --git a/tests/test_utils.py b/tests/test_utils.py index d68850a..f322119 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,7 @@ import unittest -from rapidfuzz import process, fuzz, utils +from rapidfuzz import fuzz, process, utils class UtilsTest(unittest.TestCase):