Skip to content

Commit 2ab64f6

Browse files
authored
Merge pull request #1028 from bact/dev
Update warn_deprecation to get deprecated and removal versions
2 parents d8c2e92 + 40a2c67 commit 2ab64f6

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

pythainlp/cls/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
from pythainlp.classify.param_free import GzipModel
1212
from pythainlp.tools import warn_deprecation
1313

14-
warn_deprecation("pythainlp.cls", "pythainlp.classify", "5.2")
14+
warn_deprecation("pythainlp.cls", "pythainlp.classify", "5.1", "5.2")

pythainlp/corpus/common.py

+1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def thai_synonym() -> dict:
353353
warn_deprecation(
354354
"pythainlp.corpus.thai_synonym",
355355
"pythainlp.corpus.thai_synonyms",
356+
"5.1",
356357
"5.2",
357358
)
358359
return thai_synonyms()

pythainlp/tools/core.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,26 @@
1212
def warn_deprecation(
1313
deprecated_func: str,
1414
replacing_func: str = "",
15-
version: str = "",
15+
deprecated_version: str = "",
16+
removal_version: str = "",
1617
):
1718
"""Warn about the deprecation of a function.
1819
1920
:param str deprecated_func: Name of the deprecated function.
2021
:param str replacing_func: Name of the function to use instead (optional).
21-
:param str version: PyThaiNLP version in which the function will be deprecated (optional).
22+
:param str deprecated_version: Version in which the function will be deprecated (optional).
23+
:param str removal_version: Version in which the function will be removed (optional).
2224
"""
23-
if version:
24-
version = f"PyThaiNLP {version}"
25-
else:
26-
version = "a future release"
27-
message = f"The '{deprecated_func}' function is deprecated and will be removed in {version}."
25+
message = f"The '{deprecated_func}' function is deprecated"
26+
if deprecated_version:
27+
message += f" since {deprecated_version}"
28+
if not removal_version:
29+
removal_version = "a future release"
30+
message += f" and will be removed in {removal_version}."
2831
if replacing_func:
2932
message += f" Please use '{replacing_func}' instead."
3033
warnings.warn(message, DeprecationWarning, stacklevel=2)
3134

32-
3335
def safe_print(text: str):
3436
"""Print text to console, handling UnicodeEncodeError.
3537

pythainlp/util/normalize.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ def maiyamok(sent: Union[str, List[str]]) -> List[str]:
331331
# output: ['คน', 'คน', 'นก']
332332
"""
333333
warn_deprecation(
334-
"pythainlp.util.maiyamok", "pythainlp.util.expand_maiyamok", "5.2"
334+
"pythainlp.util.maiyamok",
335+
"pythainlp.util.expand_maiyamok",
336+
"5.0.5",
337+
"5.2",
335338
)
336339
return expand_maiyamok(sent)

pythainlp/util/thaiwordcheck.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def is_native_thai(word: str) -> bool:
88
warn_deprecation(
99
"pythainlp.util.is_native_thai",
1010
"pythainlp.morpheme.is_native_thai",
11+
"5.0",
1112
"5.1",
1213
)
1314

0 commit comments

Comments
 (0)