Skip to content

Commit c9fbf57

Browse files
authored
Merge pull request #82 from life4/type-annotations
Type annotations
2 parents 4f4a713 + 6c5b26e commit c9fbf57

23 files changed

+582
-454
lines changed

.drone.star

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,22 @@ def main(ctx):
1212
"apt update",
1313
"apt install -y wget",
1414
"wget https://taskfile.dev/install.sh",
15-
"sh install.sh -- latest",
15+
"sh install.sh",
1616
"rm install.sh",
1717
],
1818
),
1919

20-
step(env="pytest-pure", python="3.6"),
2120
step(env="pytest-pure", python="3.7"),
2221
step(env="pytest-pure", python="3.8"),
2322
step(env="pytest-pure", python="3.9"),
2423
step(env="pytest-pure", python="3.10"),
2524

26-
step(env="pytest-external", python="3.6"),
2725
step(env="pytest-external", python="3.7"),
2826
step(env="pytest-external", python="3.8"),
2927
step(env="pytest-external", python="3.9"),
3028
# step(env="pytest-external", python="3.10"),
3129

32-
step(env="flake8", python="3.7"),
30+
step(env="flake8", python="3.9"),
3331
],
3432
)
3533

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ dist/
77
licenses_example/choosealicense.com
88
.hypothesis/
99
.coverage
10-
htmlcov
11-
.task/
12-
venvs/
10+
/htmlcov/
11+
/.task/
12+
/.venvs/

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -240,32 +240,32 @@ Algorithms:
240240

241241
Without extras installation:
242242

243-
| algorithm | library | function | time |
244-
|-----------|---------|----------|------|
245-
| DamerauLevenshtein | jellyfish | damerau_levenshtein_distance | 0.00965294 |
246-
| DamerauLevenshtein | pyxdameraulevenshtein | damerau_levenshtein_distance | 0.151378 |
247-
| DamerauLevenshtein | pylev | damerau_levenshtein | 0.766461 |
248-
| DamerauLevenshtein | **textdistance** | DamerauLevenshtein | 4.13463 |
249-
| DamerauLevenshtein | abydos | damerau_levenshtein | 4.3831 |
250-
| Hamming | Levenshtein | hamming | 0.0014428 |
251-
| Hamming | jellyfish | hamming_distance | 0.00240262 |
252-
| Hamming | distance | hamming | 0.036253 |
253-
| Hamming | abydos | hamming | 0.0383933 |
254-
| Hamming | **textdistance** | Hamming | 0.176781 |
255-
| Jaro | Levenshtein | jaro | 0.00313561 |
256-
| Jaro | jellyfish | jaro_distance | 0.0051885 |
257-
| Jaro | py_stringmatching | jaro | 0.180628 |
258-
| Jaro | **textdistance** | Jaro | 0.278917 |
259-
| JaroWinkler | Levenshtein | jaro_winkler | 0.00319735 |
260-
| JaroWinkler | jellyfish | jaro_winkler | 0.00540443 |
261-
| JaroWinkler | **textdistance** | JaroWinkler | 0.289626 |
262-
| Levenshtein | Levenshtein | distance | 0.00414404 |
263-
| Levenshtein | jellyfish | levenshtein_distance | 0.00601647 |
264-
| Levenshtein | py_stringmatching | levenshtein | 0.252901 |
265-
| Levenshtein | pylev | levenshtein | 0.569182 |
266-
| Levenshtein | distance | levenshtein | 1.15726 |
267-
| Levenshtein | abydos | levenshtein | 3.68451 |
268-
| Levenshtein | **textdistance** | Levenshtein | 8.63674 |
243+
| algorithm | library | time |
244+
|--------------------|-----------------------|---------|
245+
| DamerauLevenshtein | rapidfuzz | 0.00312 |
246+
| DamerauLevenshtein | jellyfish | 0.00591 |
247+
| DamerauLevenshtein | pyxdameraulevenshtein | 0.03335 |
248+
| DamerauLevenshtein | abydos | 0.63278 |
249+
| DamerauLevenshtein | **textdistance** | 0.83524 |
250+
| Hamming | Levenshtein | 0.00038 |
251+
| Hamming | rapidfuzz | 0.00044 |
252+
| Hamming | jellyfish | 0.00091 |
253+
| Hamming | distance | 0.00812 |
254+
| Hamming | abydos | 0.00902 |
255+
| Hamming | **textdistance** | 0.03531 |
256+
| Jaro | rapidfuzz | 0.00092 |
257+
| Jaro | jellyfish | 0.00191 |
258+
| Jaro | **textdistance** | 0.07365 |
259+
| JaroWinkler | rapidfuzz | 0.00094 |
260+
| JaroWinkler | jellyfish | 0.00195 |
261+
| JaroWinkler | **textdistance** | 0.07501 |
262+
| Levenshtein | rapidfuzz | 0.00099 |
263+
| Levenshtein | Levenshtein | 0.00122 |
264+
| Levenshtein | jellyfish | 0.00254 |
265+
| Levenshtein | pylev | 0.15688 |
266+
| Levenshtein | distance | 0.28669 |
267+
| Levenshtein | **textdistance** | 0.53902 |
268+
| Levenshtein | abydos | 1.25783 |
269269

270270
Total: 24 libs.
271271

Taskfile.yml

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
version: "3"
33

44
vars:
5-
PYTHON_BIN: python3.7
6-
VENVS: ./venvs/
7-
FLAKE8_ENV: "{{.VENVS}}flake8"
8-
PYTEST_PURE_ENV: "{{.VENVS}}pytest-pure"
9-
PYTEST_EXT_ENV: "{{.VENVS}}pytest-ext"
10-
ISORT_ENV: "{{.VENVS}}isort"
11-
TWINE_ENV: "{{.VENVS}}twine"
5+
PYTHON_BIN: python3
6+
VENVS: .venvs/
7+
LINT_ENV: "{{.VENVS}}lint"
8+
BENCHMARK_ENV: "{{.VENVS}}benchmark"
9+
TEST_PURE_ENV: "{{.VENVS}}pytest-pure"
10+
TEST_EXT_ENV: "{{.VENVS}}pytest-ext"
1211

1312
tasks:
1413
venv:create:
@@ -21,75 +20,75 @@ tasks:
2120
sources:
2221
- setup.py
2322
- "{{.ENV}}/bin/activate"
23+
status:
24+
- test -f {{.ENV}}/bin/flake8
2425
deps:
2526
- task: venv:create
2627
vars:
2728
ENV: "{{.ENV}}"
2829
cmds:
2930
- "{{.ENV}}/bin/pip install '.[{{.EXTRA}}]'"
3031

31-
twine:install:
32-
deps:
33-
- task: venv:create
34-
vars:
35-
ENV: "{{.TWINE_ENV}}"
32+
lint:install:
3633
cmds:
37-
- "{{.TWINE_ENV}}/bin/pip install twine"
34+
- task: pip:install
35+
vars:
36+
ENV: "{{.LINT_ENV}}"
37+
EXTRA: test,lint
38+
3839
twine:build:
3940
deps:
40-
- twine:install
41+
- lint:install
4142
cmds:
4243
- rm -rf dist/
43-
- "{{.TWINE_ENV}}/bin/python3 setup.py sdist bdist_wheel"
44+
- "{{.LINT_ENV}}/bin/python3 setup.py sdist bdist_wheel"
4445
twine:release:
4546
deps:
4647
- twine:build
4748
cmds:
48-
- "{{.TWINE_ENV}}/bin/twine upload dist/textdistance-*"
49+
- "{{.LINT_ENV}}/bin/twine upload dist/textdistance-*"
4950

50-
flake8:install:
51-
status:
52-
- "test -f {{.FLAKE8_ENV}}/bin/flake8"
51+
flake8:run:
5352
deps:
54-
- task: venv:create
55-
vars:
56-
ENV: "{{.FLAKE8_ENV}}"
53+
- lint:install
5754
cmds:
58-
- "{{.FLAKE8_ENV}}/bin/python3 -m pip install -r requirements-flake.txt"
59-
flake8:run:
60-
sources:
61-
- "**/*.py"
55+
- "{{.LINT_ENV}}/bin/flake8 ."
56+
mypy:run:
6257
deps:
63-
- flake8:install
58+
- lint:install
6459
cmds:
65-
- "{{.FLAKE8_ENV}}/bin/flake8 ."
60+
- "{{.LINT_ENV}}/bin/mypy"
6661

6762

6863
pytest-pure:run:
6964
deps:
7065
- task: pip:install
7166
vars:
72-
ENV: "{{.PYTEST_PURE_ENV}}"
67+
ENV: "{{.TEST_PURE_ENV}}"
7368
EXTRA: test
7469
cmds:
75-
- "{{.PYTEST_PURE_ENV}}/bin/pytest -m 'not external' {{.CLI_ARGS}}"
70+
- "{{.TEST_PURE_ENV}}/bin/pytest -m 'not external' {{.CLI_ARGS}}"
7671

7772
pytest-external:run:
7873
deps:
7974
- task: pip:install
8075
vars:
81-
ENV: "{{.PYTEST_EXT_ENV}}"
76+
ENV: "{{.TEST_EXT_ENV}}"
8277
EXTRA: test,benchmark
8378
cmds:
84-
- "{{.PYTEST_EXT_ENV}}/bin/pytest {{.CLI_ARGS}}"
79+
- "{{.TEST_EXT_ENV}}/bin/pytest {{.CLI_ARGS}}"
8580

8681
isort:run:
87-
sources:
88-
- "**/*.py"
82+
deps:
83+
- lint:install
84+
cmds:
85+
- "{{.LINT_ENV}}/bin/isort ."
86+
87+
benchmark:
8988
deps:
9089
- task: pip:install
9190
vars:
92-
ENV: "{{.ISORT_ENV}}"
93-
EXTRA: tests
91+
ENV: "{{.BENCHMARK_ENV}}"
92+
EXTRA: benchmark
9493
cmds:
95-
- "{{.ISORT_ENV}}/bin/isort ."
94+
- "{{.BENCHMARK_ENV}}/bin/python3 -m textdistance.benchmark"

pyproject.toml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
1-
[tool.dephell.main]
2-
from = "setup.py"
3-
tag = "v."
4-
5-
[tool.dephell.pytest-pure]
6-
from = "setup.py"
7-
envs = ["test"]
8-
command = "python3 -m pytest -m 'not external' tests/"
9-
10-
[tool.dephell.pytest-external]
11-
from = "setup.py"
12-
envs = ["test", "benchmark"]
13-
command = "python3 -m pytest tests/"
14-
15-
[tool.dephell.isort]
16-
from = "setup.py"
17-
envs = ["test"]
18-
command = "python3 -m isort -rc ."
19-
20-
[tool.dephell.flake8]
21-
from = {format = "pip", path = "requirements-flake.txt"}
22-
command = "flake8"
1+
[tool.mypy]
2+
files = ["textdistance"]
3+
python_version = 3.7
4+
show_error_codes = true
5+
disable_error_code = ["override"]
6+
warn_unused_ignores = true
7+
allow_redefinition = true
8+
check_untyped_defs = true

requirements-flake.txt

Lines changed: 0 additions & 34 deletions
This file was deleted.

setup.cfg

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ license_file = LICENSE
66
max-line-length=120
77
ignore=P101,P103,E241,B023
88
exclude=
9-
.tox,
9+
.tox
1010
.pytest_cache
11-
venvs/
11+
.venvs/
12+
build
1213

1314
[isort]
14-
skip=.tox,.pytest_cache,venvs
15+
skip=.tox,.pytest_cache,.venvs,build
1516
line_length=120
1617
combine_as_imports=true
1718
balanced_wrapping=true

setup.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@
3737
'numpy',
3838
'pytest',
3939
],
40+
'lint': [
41+
'twine',
42+
'mypy',
43+
'isort',
44+
'flake8',
45+
'types-tabulate',
46+
47+
# flake8 plugins
48+
'flake8-blind-except',
49+
'flake8-bugbear',
50+
'flake8-commas',
51+
'flake8-logging-format',
52+
'flake8-mutable',
53+
'flake8-pep3101',
54+
'flake8-quotes',
55+
'flake8-string-format',
56+
'flake8-tidy-imports',
57+
'pep8-naming',
58+
],
4059

4160
# for algos, from fastest to slowest, only faster than textdistance:
4261
'DamerauLevenshtein': [

tests/test_external.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def test_qval(left, right, alg, qval):
5858
conditions = lib.conditions or {}
5959
internal_func = getattr(textdistance, alg)(external=False, **conditions)
6060
external_func = lib.get_function()
61+
if external_func is None:
62+
raise RuntimeError('cannot import {}'.format(str(lib)))
6163
# algorithm doesn't support q-grams
6264
if not hasattr(internal_func, 'qval'):
6365
continue

0 commit comments

Comments
 (0)