Skip to content

Commit

Permalink
Add typings
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanforbes committed Dec 4, 2019
1 parent 70c0a5f commit 57aba99
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ dist/
htmlcov/
.tox/
build/
.mypy_cache/
.venv/
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,19 @@ script:
- coverage run --append --branch --source pyuca full_test.py
after_success:
- coveralls
jobs:
include:
- name: "check typings"
python: 3.8
install: |
set -e
pip install mypy
script: |
set -e
mypy --python-version 3.8 pyuca
mypy --python-version 3.7 pyuca
mypy --python-version 3.6 pyuca
mypy --python-version 3.5 pyuca
mypy --python-version 3.4 pyuca
mypy --python-version 2.7 pyuca
sudo: false
16 changes: 16 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[mypy]
incremental = True
warn_unused_configs = True
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
disallow_untyped_decorators = True
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
no_implicit_reexport = True
disallow_any_unimported = True
1 change: 1 addition & 0 deletions pyuca/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .collator import Collator as Collator # noqa
64 changes: 64 additions & 0 deletions pyuca/collator.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
from typing import List, Optional, Tuple, ClassVar
from .trie import Trie

class BaseCollator:
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
CJK_IDEOGRAPHS_10_0_0: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_A: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_B: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_C: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_D: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_F: ClassVar[bool] = ...
table: Trie
implicit_weights: List[List[int]] = ...
def __init__(self, filename: Optional[str] = ...) -> None: ...
def load(self, filename: str) -> None: ...
def collation_elements(
self,
normalized_string: str
) -> List[List[int]]: ...
def sort_key_from_collation_elements(
self,
collation_elements: List[List[int]]
) -> Tuple[int, ...]: ...
def sort_key(self, string: str) -> Tuple[int, ...]: ...
def implicit_weight(self, cp: int) -> List[List[int]]: ...
def build_lookup_key(self, text: str) -> List[int]: ...

class Collator_6_3_0(BaseCollator):
UCA_VERSION: ClassVar[str] = ...

class Collator_8_0_0(BaseCollator):
UCA_VERSION: ClassVar[str] = ...
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...

class Collator_9_0_0(BaseCollator):
UCA_VERSION: ClassVar[str] = ...
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...

class Collator_10_0_0(BaseCollator):
UCA_VERSION: ClassVar[str] = ...
CJK_IDEOGRAPHS_8_0_0: ClassVar[bool] = ...
CJK_IDEOGRAPHS_10_0_0: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_E: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_F: ClassVar[bool] = ...

class Collator_5_2_0(BaseCollator):
UCA_VERSION: ClassVar[str] = ...
CJK_IDEOGRAPHS_EXT_C: ClassVar[bool] = ...
CJK_IDEOGRAPHS_EXT_D: ClassVar[bool] = ...
non_char_code_points: ClassVar[List[int]] = ...
def build_lookup_key(self, text: str) -> List[int]: ...

if sys.version_info < (3,):
Collator = Collator_5_2_0
elif sys.version_info[:2] == (3, 5):
Collator = Collator_8_0_0
elif sys.version_info[:2] >= (3, 6):
Collator = Collator_9_0_0
else:
Collator = Collator_6_3_0
Empty file added pyuca/py.typed
Empty file.
15 changes: 15 additions & 0 deletions pyuca/trie.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import List, Optional, Tuple, Dict

class Node:
value: Optional[List[List[int]]]
children: Optional[Dict[int, Node]]
def __init__(self) -> None: ...

class Trie:
root: Node
def __init__(self) -> None: ...
def add(self, key: List[int], value: List[List[int]]) -> None: ...
def find_prefix(
self,
key: List[int]
) -> Tuple[List[int], Optional[List[List[int]]], List[int]]: ...
8 changes: 8 additions & 0 deletions pyuca/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Iterable, List, Optional

def hexstrings2int(hexstrings: Iterable[str]) -> List[int]: ...
def int2hexstrings(number_list: Iterable[int]) -> List[str]: ...
def format_collation_elements(
collation_elements: Optional[List[List[int]]]
) -> Optional[str]: ...
def format_sort_key(sort_key: List[int]) -> str: ...
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
author_email="jtauber@jtauber.com",
packages=["pyuca"],
package_data={"": [
"py.typed",
"allkeys-5.2.0.txt",
"allkeys-6.3.0.txt",
"allkeys-8.0.0.txt",
Expand Down

0 comments on commit 57aba99

Please sign in to comment.