Skip to content

Update warn_deprecation to get deprecated and removal versions #1028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading