From 794ec0fc4779213202f7a44c7ddec35bc8d937be Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Fri, 13 Dec 2024 12:45:56 +0000 Subject: [PATCH 1/3] Update warn_deprecation to get deprecated and removal versions --- pythainlp/tools/core.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pythainlp/tools/core.py b/pythainlp/tools/core.py index 11da241b1..02fe8d745 100644 --- a/pythainlp/tools/core.py +++ b/pythainlp/tools/core.py @@ -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: PyThaiNLP version in which the function will be deprecated (optional). + :param str removal_version: PyThaiNLP 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. From 88afae536f340d2b58a8fbcde3d253df17eff500 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Fri, 13 Dec 2024 12:54:55 +0000 Subject: [PATCH 2/3] Update warn_deprecation parameters --- pythainlp/cls/__init__.py | 2 +- pythainlp/corpus/common.py | 1 + pythainlp/util/normalize.py | 5 ++++- pythainlp/util/thaiwordcheck.py | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pythainlp/cls/__init__.py b/pythainlp/cls/__init__.py index 110371cdc..d036cef1d 100644 --- a/pythainlp/cls/__init__.py +++ b/pythainlp/cls/__init__.py @@ -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") diff --git a/pythainlp/corpus/common.py b/pythainlp/corpus/common.py index 2bde21aba..b8d6be952 100644 --- a/pythainlp/corpus/common.py +++ b/pythainlp/corpus/common.py @@ -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() diff --git a/pythainlp/util/normalize.py b/pythainlp/util/normalize.py index 153909e3d..d03f7c7b3 100644 --- a/pythainlp/util/normalize.py +++ b/pythainlp/util/normalize.py @@ -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) diff --git a/pythainlp/util/thaiwordcheck.py b/pythainlp/util/thaiwordcheck.py index a6f49db13..a67071e70 100644 --- a/pythainlp/util/thaiwordcheck.py +++ b/pythainlp/util/thaiwordcheck.py @@ -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", ) From 40a2c674976c6db03b10d3f1e3c721c105c83ce7 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Fri, 13 Dec 2024 14:30:38 +0000 Subject: [PATCH 3/3] Update core.py --- pythainlp/tools/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pythainlp/tools/core.py b/pythainlp/tools/core.py index 02fe8d745..be4cf5cfc 100644 --- a/pythainlp/tools/core.py +++ b/pythainlp/tools/core.py @@ -19,8 +19,8 @@ def warn_deprecation( :param str deprecated_func: Name of the deprecated function. :param str replacing_func: Name of the function to use instead (optional). - :param str deprecated_version: PyThaiNLP version in which the function will be deprecated (optional). - :param str removal_version: PyThaiNLP version in which the function will be removed (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). """ message = f"The '{deprecated_func}' function is deprecated" if deprecated_version: