Skip to content

Commit e39d13b

Browse files
committed
Add typings
1 parent 70c0a5f commit e39d13b

9 files changed

+124
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ dist/
66
htmlcov/
77
.tox/
88
build/
9+
.mypy_cache/
10+
.venv/

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,21 @@ script:
1616
- coverage run --append --branch --source pyuca full_test.py
1717
after_success:
1818
- coveralls
19+
jobs:
20+
include:
21+
- name: "check typings"
22+
python: 3.8
23+
install: |
24+
set -e
25+
pip install mypy
26+
script: |
27+
set -e
28+
mypy --python-version 3.8 pyuca
29+
mypy --python-version 3.7 pyuca
30+
mypy --python-version 3.6 pyuca
31+
mypy --python-version 3.5 pyuca
32+
mypy --python-version 3.4 pyuca
33+
mypy --python-version 2.7 pyuca
34+
after_success: |
35+
echo "done"
1936
sudo: false

mypy.ini

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[mypy]
2+
incremental = True
3+
warn_unused_configs = True
4+
disallow_any_generics = True
5+
disallow_subclassing_any = True
6+
disallow_untyped_calls = True
7+
disallow_untyped_defs = True
8+
disallow_incomplete_defs = True
9+
check_untyped_defs = True
10+
disallow_untyped_decorators = True
11+
no_implicit_optional = True
12+
warn_redundant_casts = True
13+
warn_unused_ignores = True
14+
warn_return_any = True
15+
no_implicit_reexport = True
16+
disallow_any_unimported = True

pyuca/__init__.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .collator import Collator as Collator # noqa

pyuca/collator.pyi

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import sys
2+
from typing import List, Optional, Tuple, ClassVar
3+
from .trie import Trie
4+
5+
class BaseCollator:
6+
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
7+
CJK_IDEOGRAPHS_10_0_0: ClassVar[bool] = ...
8+
CJK_IDEOGRAPHS_EXT_A: ClassVar[bool] = ...
9+
CJK_IDEOGRAPHS_EXT_B: ClassVar[bool] = ...
10+
CJK_IDEOGRAPHS_EXT_C: ClassVar[bool] = ...
11+
CJK_IDEOGRAPHS_EXT_D: ClassVar[bool] = ...
12+
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...
13+
CJK_IDEOGRAPHS_EXT_F: ClassVar[bool] = ...
14+
table: Trie
15+
implicit_weights: List[List[int]] = ...
16+
def __init__(self, filename: Optional[str] = ...) -> None: ...
17+
def load(self, filename: str) -> None: ...
18+
def collation_elements(
19+
self,
20+
normalized_string: str
21+
) -> List[List[int]]: ...
22+
def sort_key_from_collation_elements(
23+
self,
24+
collation_elements: List[List[int]]
25+
) -> Tuple[int, ...]: ...
26+
def sort_key(self, string: str) -> Tuple[int, ...]: ...
27+
def implicit_weight(self, cp: int) -> List[List[int]]: ...
28+
def build_lookup_key(self, text: str) -> List[int]: ...
29+
30+
class Collator_6_3_0(BaseCollator):
31+
UCA_VERSION: ClassVar[str] = ...
32+
33+
class Collator_8_0_0(BaseCollator):
34+
UCA_VERSION: ClassVar[str] = ...
35+
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
36+
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...
37+
38+
class Collator_9_0_0(BaseCollator):
39+
UCA_VERSION: ClassVar[str] = ...
40+
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
41+
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...
42+
43+
class Collator_10_0_0(BaseCollator):
44+
UCA_VERSION: ClassVar[str] = ...
45+
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
46+
CJK_IDEOGRAPHS_10_0_0: ClassVar[bool] = ...
47+
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...
48+
CJK_IDEOGRAPHS_EXT_F: ClassVar[bool] = ...
49+
50+
class Collator_5_2_0(BaseCollator):
51+
UCA_VERSION: ClassVar[str] = ...
52+
CJK_IDEOGRAPHS_EXT_C: ClassVar[bool] = ...
53+
CJK_IDEOGRAPHS_EXT_D: ClassVar[bool] = ...
54+
non_char_code_points: ClassVar[List[int]] = ...
55+
def build_lookup_key(self, text: str) -> List[int]: ...
56+
57+
if sys.version_info < (3,):
58+
Collator = Collator_5_2_0
59+
elif sys.version_info[:2] == (3, 5):
60+
Collator = Collator_8_0_0
61+
elif sys.version_info[:2] >= (3, 6):
62+
Collator = Collator_9_0_0
63+
else:
64+
Collator = Collator_6_3_0

pyuca/py.typed

Whitespace-only changes.

pyuca/trie.pyi

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List, Optional, Tuple, Dict
2+
3+
class Node:
4+
value: Optional[List[List[int]]]
5+
children: Optional[Dict[int, Node]]
6+
def __init__(self) -> None: ...
7+
8+
class Trie:
9+
root: Node
10+
def __init__(self) -> None: ...
11+
def add(self, key: List[int], value: List[List[int]]) -> None: ...
12+
def find_prefix(
13+
self,
14+
key: List[int]
15+
) -> Tuple[List[int], Optional[List[List[int]]], List[int]]: ...

pyuca/utils.pyi

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import Iterable, List, Optional
2+
3+
def hexstrings2int(hexstrings: Iterable[str]) -> List[int]: ...
4+
def int2hexstrings(number_list: Iterable[int]) -> List[str]: ...
5+
def format_collation_elements(
6+
collation_elements: Optional[List[List[int]]]
7+
) -> Optional[str]: ...
8+
def format_sort_key(sort_key: List[int]) -> str: ...

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
author_email="[email protected]",
1111
packages=["pyuca"],
1212
package_data={"": [
13+
"py.typed",
1314
"allkeys-5.2.0.txt",
1415
"allkeys-6.3.0.txt",
1516
"allkeys-8.0.0.txt",

0 commit comments

Comments
 (0)