Skip to content

Commit

Permalink
Merge pull request #1028 from bact/dev
Browse files Browse the repository at this point in the history
Update warn_deprecation to get deprecated and removal versions
  • Loading branch information
bact authored Dec 13, 2024
2 parents d8c2e92 + 40a2c67 commit 2ab64f6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pythainlp/cls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
from pythainlp.classify.param_free import GzipModel
from pythainlp.tools import warn_deprecation

warn_deprecation("pythainlp.cls", "pythainlp.classify", "5.2")
warn_deprecation("pythainlp.cls", "pythainlp.classify", "5.1", "5.2")
1 change: 1 addition & 0 deletions pythainlp/corpus/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def thai_synonym() -> dict:
warn_deprecation(
"pythainlp.corpus.thai_synonym",
"pythainlp.corpus.thai_synonyms",
"5.1",
"5.2",
)
return thai_synonyms()
Expand Down
18 changes: 10 additions & 8 deletions pythainlp/tools/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@
def warn_deprecation(
deprecated_func: str,
replacing_func: str = "",
version: str = "",
deprecated_version: str = "",
removal_version: str = "",
):
"""Warn about the deprecation of a function.
:param str deprecated_func: Name of the deprecated function.
:param str replacing_func: Name of the function to use instead (optional).
:param str version: PyThaiNLP version in which the function will be deprecated (optional).
:param str deprecated_version: Version in which the function will be deprecated (optional).
:param str removal_version: Version in which the function will be removed (optional).
"""
if version:
version = f"PyThaiNLP {version}"
else:
version = "a future release"
message = f"The '{deprecated_func}' function is deprecated and will be removed in {version}."
message = f"The '{deprecated_func}' function is deprecated"
if deprecated_version:
message += f" since {deprecated_version}"
if not removal_version:
removal_version = "a future release"
message += f" and will be removed in {removal_version}."
if replacing_func:
message += f" Please use '{replacing_func}' instead."
warnings.warn(message, DeprecationWarning, stacklevel=2)


def safe_print(text: str):
"""Print text to console, handling UnicodeEncodeError.
Expand Down
5 changes: 4 additions & 1 deletion pythainlp/util/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ def maiyamok(sent: Union[str, List[str]]) -> List[str]:
# output: ['คน', 'คน', 'นก']
"""
warn_deprecation(
"pythainlp.util.maiyamok", "pythainlp.util.expand_maiyamok", "5.2"
"pythainlp.util.maiyamok",
"pythainlp.util.expand_maiyamok",
"5.0.5",
"5.2",
)
return expand_maiyamok(sent)
1 change: 1 addition & 0 deletions pythainlp/util/thaiwordcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def is_native_thai(word: str) -> bool:
warn_deprecation(
"pythainlp.util.is_native_thai",
"pythainlp.morpheme.is_native_thai",
"5.0",
"5.1",
)

Expand Down

0 comments on commit 2ab64f6

Please sign in to comment.