Skip to content

Commit 269aa64

Browse files
authored
Merge pull request #8 from devjerry0/refactor/future-annotations
Refactor/future annotations
2 parents cff7f8e + cfdde13 commit 269aa64

File tree

12 files changed

+32
-9
lines changed

12 files changed

+32
-9
lines changed

contractions/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import warnings
24

35
from ._version import __version__

contractions/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.3.1"
1+
__version__ = "0.3.2"
22

contractions/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .extension import add_custom_contraction, add_custom_dict, load_custom_from_file, load_custom_from_folder
24
from .processor import expand as _expand
35
from .processor import preview as _preview

contractions/bootstrap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .file_loader import load_dict_data, load_list_data
24
from .transformer import build_apostrophe_variants, normalize_apostrophes
35

contractions/extension.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .file_loader import load_dict_from_file, load_dict_from_folder
24
from .matcher import (
35
_get_basic_matcher,
@@ -31,11 +33,9 @@ def add_custom_dict(contractions_dict: dict[str, str]) -> None:
3133

3234

3335
def load_custom_from_file(filepath: str) -> None:
34-
contractions_data = load_dict_from_file(filepath)
35-
add_custom_dict(contractions_data)
36+
add_custom_dict(load_dict_from_file(filepath))
3637

3738

3839
def load_custom_from_folder(folderpath: str) -> None:
39-
contractions_data = load_dict_from_folder(folderpath)
40-
add_custom_dict(contractions_data)
40+
add_custom_dict(load_dict_from_folder(folderpath))
4141

contractions/file_loader.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import json
24
import pkgutil
35

@@ -15,7 +17,7 @@ def load_dict_data(filename: str) -> dict[str, str]:
1517
data = json.loads(json_bytes.decode("utf-8"))
1618
validate_data_type(data, dict, filename)
1719

18-
return cast("dict[str, str]", data)
20+
return cast(dict[str, str], data)
1921

2022

2123
def load_list_data(filename: str) -> list[str]:
@@ -26,7 +28,7 @@ def load_list_data(filename: str) -> list[str]:
2628
data = json.loads(json_bytes.decode("utf-8"))
2729
validate_data_type(data, list, filename)
2830

29-
return cast("list[str]", data)
31+
return cast(list[str], data)
3032

3133

3234
def load_dict_from_file(filepath: str) -> dict[str, str]:
@@ -36,7 +38,7 @@ def load_dict_from_file(filepath: str) -> dict[str, str]:
3638

3739
contractions_data = json.loads(path.read_text(encoding="utf-8"))
3840
validate_file_contains_dict(contractions_data, filepath)
39-
return cast("dict[str, str]", contractions_data)
41+
return cast(dict[str, str], contractions_data)
4042

4143

4244
def load_dict_from_folder(folderpath: str) -> dict[str, str]:

contractions/matcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from itertools import chain
24

35
from textsearch import TextSearch

contractions/processor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .matcher import (
24
_get_basic_matcher,
35
_get_leftovers_matcher,

contractions/state.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from textsearch import TextSearch
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING: # pragma: no cover
6+
from textsearch import TextSearch
27

38

49
class _State:

contractions/transformer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from itertools import product
24

35

0 commit comments

Comments
 (0)