Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions thefuzz/fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def _rapidfuzz_scorer(scorer, s1, s2, force_ascii, full_process):
return int(round(scorer(s1, s2)))


def ratio(s1, s2):
def ratio(s1: str, s2: str):
return _rapidfuzz_scorer(_ratio, s1, s2, False, False)


def partial_ratio(s1, s2):
def partial_ratio(s1: str, s2: str):
"""
Return the ratio of the most similar substring
as a number between 0 and 100.
Expand All @@ -52,15 +52,15 @@ def partial_ratio(s1, s2):
# find all alphanumeric tokens in the string
# sort those tokens and take ratio of resulting joined strings
# controls for unordered string elements
def token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
def token_sort_ratio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True):
"""
Return a measure of the sequences' similarity between 0 and 100
but sorting the token before comparing.
"""
return _rapidfuzz_scorer(_token_sort_ratio, s1, s2, force_ascii, full_process)


def partial_token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
def partial_token_sort_ratio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True):
"""
Return the ratio of the most similar substring as a number between
0 and 100 but sorting the token before comparing.
Expand All @@ -70,11 +70,11 @@ def partial_token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
)


def token_set_ratio(s1, s2, force_ascii=True, full_process=True):
def token_set_ratio(s1: str, s2: str, force_ascii=True, full_process=True):
return _rapidfuzz_scorer(_token_set_ratio, s1, s2, force_ascii, full_process)


def partial_token_set_ratio(s1, s2, force_ascii=True, full_process=True):
def partial_token_set_ratio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True):
return _rapidfuzz_scorer(
_partial_token_set_ratio, s1, s2, force_ascii, full_process
)
Expand All @@ -85,7 +85,7 @@ def partial_token_set_ratio(s1, s2, force_ascii=True, full_process=True):
###################

# q is for quick
def QRatio(s1, s2, force_ascii=True, full_process=True):
def QRatio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True):
"""
Quick ratio comparison between two strings.

Expand All @@ -101,7 +101,7 @@ def QRatio(s1, s2, force_ascii=True, full_process=True):
return _rapidfuzz_scorer(_QRatio, s1, s2, force_ascii, full_process)


def UQRatio(s1, s2, full_process=True):
def UQRatio(s1: str, s2: str, full_process: bool = True):
"""
Unicode quick ratio

Expand All @@ -115,7 +115,7 @@ def UQRatio(s1, s2, full_process=True):


# w is for weighted
def WRatio(s1, s2, force_ascii=True, full_process=True):
def WRatio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True):
"""
Return a measure of the sequences' similarity between 0 and 100, using different algorithms.

Expand Down Expand Up @@ -152,7 +152,7 @@ def WRatio(s1, s2, force_ascii=True, full_process=True):
return _rapidfuzz_scorer(_WRatio, s1, s2, force_ascii, full_process)


def UWRatio(s1, s2, full_process=True):
def UWRatio(s1: str, s2: str, full_process: bool = True):
"""
Return a measure of the sequences' similarity between 0 and 100,
using different algorithms. Same as WRatio but preserving unicode.
Expand Down
10 changes: 0 additions & 10 deletions thefuzz/fuzz.pyi

This file was deleted.

4 changes: 2 additions & 2 deletions thefuzz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
translation_table = {i: None for i in range(128, 256)} # ascii dammit!


def ascii_only(s):
def ascii_only(s: str) -> str:
return s.translate(translation_table)


def full_process(s, force_ascii=False):
def full_process(s: str, force_ascii: bool = False) -> str:
"""
Process string by
-- removing all but letters and numbers
Expand Down
3 changes: 0 additions & 3 deletions thefuzz/utils.pyi

This file was deleted.