Skip to content

Commit

Permalink
fix type hints (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann authored Feb 11, 2022
1 parent 4444f34 commit 5671414
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 151 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/branchbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
name: "Python ${{ matrix.python-version }}"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
python-version: ["3.6", "3.9", "3.10"]
os: [ubuntu-latest, windows-latest, macos-latest]
Expand All @@ -25,14 +26,19 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest hypothesis pandas
pip install pytest hypothesis pandas mypy
- name: build
run: |
pip install build; python -m build --sdist
# test whether tarball contains all files required for compiling
pip install dist/rapidfuzz-*.tar.gz
- name: Test type stubs
if: matrix.python-version != '3.6'
run: |
python -m mypy.stubtest rapidfuzz --ignore-missing-stub
- name: Test with pytest
run: |
pytest tests
19 changes: 16 additions & 3 deletions .github/workflows/releasebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,25 @@ jobs:

- uses: actions/setup-python@v2

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest hypothesis pandas mypy
- name: Build sdist
run: |
pip3 install build; python3 -m build --sdist
pip install build
python -m build --sdist
# test whether tarball contains all files required for compiling
pip3 install dist/rapidfuzz-*.tar.gz
pip3 uninstall rapidfuzz --yes
pip install dist/rapidfuzz-*.tar.gz
- name: Test type stubs
run: |
python -m mypy.stubtest rapidfuzz --ignore-missing-stub
- name: Test with pytest
run: |
pytest tests
- uses: actions/upload-artifact@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
include MANIFEST.in
include setup.py
include CMakeLists.txt
include README.md
include LICENSE
include pyproject.toml
include src/rapidfuzz/*.pyi
include src/rapidfuzz/**/*.pyi
include src/rapidfuzz/py.typed

Expand Down
12 changes: 6 additions & 6 deletions src/rapidfuzz/distance/Hamming.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ S2 = TypeVar("S2")

def distance(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
max: Optional[int] = None) -> int: ...
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[int] = None) -> int: ...

def normalized_distance(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...

def similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
max: Optional[int] = None) -> int: ...
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[int] = None) -> int: ...

def normalized_similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...
16 changes: 8 additions & 8 deletions src/rapidfuzz/distance/Indel.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ S2 = TypeVar("S2")

def distance(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
max: Optional[int] = None) -> int: ...
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[int] = None) -> int: ...

def normalized_distance(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...

def similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
max: Optional[int] = None) -> int: ...
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[int] = None) -> int: ...

def normalized_similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...

def editops(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None) -> Editops: ...
processor: Optional[Callable[..., _StringType]] = None) -> Editops: ...

def opcodes(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None) -> Opcodes: ...
processor: Optional[Callable[..., _StringType]] = None) -> Opcodes: ...
2 changes: 1 addition & 1 deletion src/rapidfuzz/distance/Jaro.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ S2 = TypeVar("S2")

def similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...
5 changes: 3 additions & 2 deletions src/rapidfuzz/distance/JaroWinkler.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Callable, Hashable, Sequence, Optional, Union, TypeVar
from typing import Callable, Hashable, Sequence, Optional, TypeVar

_StringType = Sequence[Hashable]
S1 = TypeVar("S1")
S2 = TypeVar("S2")

def similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
prefix_weight: float = 0.1,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...
22 changes: 13 additions & 9 deletions src/rapidfuzz/distance/Levenshtein.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Hashable, Sequence, Optional, Union, TypeVar, Tuple, List
from typing import Callable, Hashable, Sequence, Optional, TypeVar, Tuple
from rapidfuzz.distance import Editops, Opcodes

_StringType = Sequence[Hashable]
Expand All @@ -7,28 +7,32 @@ S2 = TypeVar("S2")

def distance(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
max: Optional[int] = None) -> int: ...
weights: Optional[Tuple[int, int, int]] = (1,1,1),
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[int] = None) -> int: ...

def normalized_distance(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
weights: Optional[Tuple[int, int, int]] = (1,1,1),
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...

def similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
max: Optional[int] = None) -> int: ...
weights: Optional[Tuple[int, int, int]] = (1,1,1),
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[int] = None) -> int: ...

def normalized_similarity(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
weights: Optional[Tuple[int, int, int]] = (1,1,1),
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...

def editops(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None) -> Editops: ...
processor: Optional[Callable[..., _StringType]] = None) -> Editops: ...

def opcodes(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None) -> Opcodes: ...
processor: Optional[Callable[..., _StringType]] = None) -> Opcodes: ...
72 changes: 50 additions & 22 deletions src/rapidfuzz/distance/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
from typing import Tuple, List, Union, overload
from typing import Tuple, List, Union

_AnyOpList = Union[
List[Union[Editop, Tuple[str, int, int]]],
List[Union[Opcode, Tuple[str, int, int, int, int]]]
]

class Editop:
tag: str
src_pos: int
dest_pos: int

def __init__(self, tag: str, src_pos: int, dest_pos: int) -> None: ...

def __len__(self) -> int: ...

def __eq__(self, other: object) -> bool: ...

def __getitem__(self, i: int) -> Union[str, int]: ...

def __repr__(self) -> str: ...


class Editops:
def __init__(self, editops: _AnyOpList = None, src_len: int = 0, dest_len: int = 0) -> None: ...

@classmethod
def from_opcodes(cls, other: Opcodes) -> Editops: ...
def from_opcodes(cls, opcodes: Opcodes) -> Editops: ...

def as_opcodes(self) -> Opcodes: ...

def as_list(self) -> List[Tuple[str, int, int]]: ...

def __eq__(self, other: Editops) -> bool: ...
def __eq__(self, other: object) -> bool: ...

def __len__(self) -> int: ...

Expand All @@ -20,35 +43,46 @@ class Editops:
def src_len(self) -> int: ...

@src_len.setter
def src_len(self, value: int): ...
def src_len(self, value: int) -> None: ...

@property
def dest_len(self) -> int: ...

@dest_len.setter
def dest_len(self, value: int): ...
def dest_len(self, value: int) -> None: ...

def __getitem__(self, key: int) -> Editop: ...

def __eq__(self, other) -> bool: ...
def __repr__(self) -> str: ...

def __setitem__(self, index: int, value: Tuple[str, int, int]): ...
class Opcode:
tag: str
src_start: int
src_end: int
dest_start: int
dest_end: int

@overload
def __getitem__(self, key: slice) -> Editops: ...
def __init__(self, tag: str, src_start: int, src_end: int, dest_start: int, dest_end: int) -> None: ...

def __len__(self) -> int: ...

@overload
def __getitem__(self, key: int) -> Tuple[str, int, int]: ...
def __eq__(self, other: object) -> bool: ...

def __getitem__(self, i: int) -> Union[str, int]: ...

def __repr__(self) -> str: ...

class Opcodes:
def __init__(self, opcodes: _AnyOpList = None, src_len: int = 0, dest_len: int = 0) -> None: ...

@classmethod
def from_editops(cls, other: Editops) -> Opcodes: ...
def from_editops(cls, editops: Editops) -> Opcodes: ...

def as_editops(self) -> Editops: ...

def as_list(self) -> List[Tuple[str, int, int, int, int]]: ...

def __eq__(self, other: Opcodes) -> bool: ...
def __eq__(self, other: object) -> bool: ...

def __len__(self) -> int: ...

Expand All @@ -60,20 +94,14 @@ class Opcodes:
def src_len(self) -> int: ...

@src_len.setter
def src_len(self, value: int): ...
def src_len(self, value: int) -> None: ...

@property
def dest_len(self) -> int: ...

@dest_len.setter
def dest_len(self, value: int): ...

def __setitem__(self, index: int, value: Tuple[str, int, int, int, int]): ...

@overload
def __getitem__(self, key: slice) -> Opcodes: ...
def dest_len(self, value: int) -> None: ...

@overload
def __getitem__(self, key: int) -> Tuple[str, int, int, int, int]: ...
def __getitem__(self, key: int) -> Opcode: ...

def __repr__(self) -> str: ...
20 changes: 10 additions & 10 deletions src/rapidfuzz/fuzz.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@ S2 = TypeVar("S2")

def ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...

def partial_ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = None,
processor: Optional[Callable[..., _StringType]] = None,
score_cutoff: Optional[float] = 0) -> float: ...

def token_sort_ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...

def token_set_ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...

def token_ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...

def partial_token_sort_ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...

def partial_token_set_ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...

def partial_token_ratio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...

def WRatio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...

def QRatio(
s1: S1, s2: S2, *,
processor: Optional[Callable[[Union[S1, S2]], _StringType]] = default_process,
processor: Optional[Callable[..., _StringType]] = default_process,
score_cutoff: Optional[float] = 0) -> float: ...
Loading

0 comments on commit 5671414

Please sign in to comment.