diff --git a/contractions/__init__.py b/contractions/__init__.py index 19cbf35..2ed0101 100644 --- a/contractions/__init__.py +++ b/contractions/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import warnings from ._version import __version__ diff --git a/contractions/_version.py b/contractions/_version.py index 8278a8e..e9ba10a 100644 --- a/contractions/_version.py +++ b/contractions/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.3.1" +__version__ = "0.3.2" diff --git a/contractions/api.py b/contractions/api.py index b956dc7..d3c6a4e 100644 --- a/contractions/api.py +++ b/contractions/api.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from .extension import add_custom_contraction, add_custom_dict, load_custom_from_file, load_custom_from_folder from .processor import expand as _expand from .processor import preview as _preview diff --git a/contractions/bootstrap.py b/contractions/bootstrap.py index d1dbbf9..ae09e88 100644 --- a/contractions/bootstrap.py +++ b/contractions/bootstrap.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from .file_loader import load_dict_data, load_list_data from .transformer import build_apostrophe_variants, normalize_apostrophes diff --git a/contractions/extension.py b/contractions/extension.py index 00fa4ff..e29ee0e 100644 --- a/contractions/extension.py +++ b/contractions/extension.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from .file_loader import load_dict_from_file, load_dict_from_folder from .matcher import ( _get_basic_matcher, @@ -31,11 +33,9 @@ def add_custom_dict(contractions_dict: dict[str, str]) -> None: def load_custom_from_file(filepath: str) -> None: - contractions_data = load_dict_from_file(filepath) - add_custom_dict(contractions_data) + add_custom_dict(load_dict_from_file(filepath)) def load_custom_from_folder(folderpath: str) -> None: - contractions_data = load_dict_from_folder(folderpath) - add_custom_dict(contractions_data) + add_custom_dict(load_dict_from_folder(folderpath)) diff --git a/contractions/file_loader.py b/contractions/file_loader.py index 0f3987e..032b5c2 100644 --- a/contractions/file_loader.py +++ b/contractions/file_loader.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json import pkgutil @@ -15,7 +17,7 @@ def load_dict_data(filename: str) -> dict[str, str]: data = json.loads(json_bytes.decode("utf-8")) validate_data_type(data, dict, filename) - return cast("dict[str, str]", data) + return cast(dict[str, str], data) def load_list_data(filename: str) -> list[str]: @@ -26,7 +28,7 @@ def load_list_data(filename: str) -> list[str]: data = json.loads(json_bytes.decode("utf-8")) validate_data_type(data, list, filename) - return cast("list[str]", data) + return cast(list[str], data) def load_dict_from_file(filepath: str) -> dict[str, str]: @@ -36,7 +38,7 @@ def load_dict_from_file(filepath: str) -> dict[str, str]: contractions_data = json.loads(path.read_text(encoding="utf-8")) validate_file_contains_dict(contractions_data, filepath) - return cast("dict[str, str]", contractions_data) + return cast(dict[str, str], contractions_data) def load_dict_from_folder(folderpath: str) -> dict[str, str]: diff --git a/contractions/matcher.py b/contractions/matcher.py index c8c5313..a473da3 100644 --- a/contractions/matcher.py +++ b/contractions/matcher.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from itertools import chain from textsearch import TextSearch diff --git a/contractions/processor.py b/contractions/processor.py index 7590b0d..d95bddf 100644 --- a/contractions/processor.py +++ b/contractions/processor.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from .matcher import ( _get_basic_matcher, _get_leftovers_matcher, diff --git a/contractions/state.py b/contractions/state.py index e016b50..8008a5e 100644 --- a/contractions/state.py +++ b/contractions/state.py @@ -1,4 +1,9 @@ -from textsearch import TextSearch +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: # pragma: no cover + from textsearch import TextSearch class _State: diff --git a/contractions/transformer.py b/contractions/transformer.py index 082486e..3a24d5e 100644 --- a/contractions/transformer.py +++ b/contractions/transformer.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from itertools import product diff --git a/contractions/validation.py b/contractions/validation.py index 2084456..480f568 100644 --- a/contractions/validation.py +++ b/contractions/validation.py @@ -1,3 +1,6 @@ +from __future__ import annotations + + def validate_string_param(value: object, param_name: str) -> None: if not isinstance(value, str): raise TypeError(f"{param_name} must be a string, got {type(value).__name__}") diff --git a/pyproject.toml b/pyproject.toml index f71c1fe..2937f9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -155,6 +155,7 @@ ignore = [ "PLR0913", "PLR2004", "PLR6104", + "TC006", ] [tool.ruff.lint.mccabe]