From b804d4132dcb9853c86026f0fce7773e50b98ad3 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Fri, 13 Dec 2024 14:41:23 +0000 Subject: [PATCH] Use warn_deprecated --- pythainlp/cls/__init__.py | 6 ++---- pythainlp/corpus/common.py | 15 ++++++++++----- pythainlp/phayathaibert/core.py | 2 +- pythainlp/tools/core.py | 4 ++-- pythainlp/util/thaiwordcheck.py | 16 +++++++++------- pythainlp/wangchanberta/core.py | 2 +- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/pythainlp/cls/__init__.py b/pythainlp/cls/__init__.py index d4cc162f7..d036cef1d 100644 --- a/pythainlp/cls/__init__.py +++ b/pythainlp/cls/__init__.py @@ -5,12 +5,10 @@ pythainlp.cls Depreciated. Use pythainlp.classify instead. """ -import warnings __all__ = ["GzipModel"] from pythainlp.classify.param_free import GzipModel +from pythainlp.tools import warn_deprecation -warnings.warn( - "Deprecated: Use pythainlp.classify instead.", DeprecationWarning -) +warn_deprecation("pythainlp.cls", "pythainlp.classify", "5.1", "5.2") diff --git a/pythainlp/corpus/common.py b/pythainlp/corpus/common.py index a44544aa6..8c822d843 100644 --- a/pythainlp/corpus/common.py +++ b/pythainlp/corpus/common.py @@ -24,9 +24,9 @@ ] from typing import FrozenSet, List, Union -import warnings from pythainlp.corpus import get_corpus, get_corpus_as_is, get_corpus_path +from pythainlp.tools import warn_deprecation _THAI_COUNTRIES: FrozenSet[str] = frozenset() _THAI_COUNTRIES_FILENAME = "countries_th.txt" @@ -56,9 +56,9 @@ _THAI_ORST_WORDS: FrozenSet[str] = frozenset() -_THAI_DICT = {} -_THAI_WSD_DICT = {} -_THAI_SYNONYMS = {} +_THAI_DICT: dict[str, list] = {} +_THAI_WSD_DICT: dict[str, list] = {} +_THAI_SYNONYMS: dict[str, list] = {} def countries() -> FrozenSet[str]: @@ -336,7 +336,12 @@ def thai_synonyms() -> dict: def thai_synonym() -> dict: - warnings.warn("Deprecated: Use thai_synonyms() instead.", DeprecationWarning) + warn_deprecation( + "pythainlp.corpus.thai_synonym", + "pythainlp.corpus.thai_synonyms", + "5.1", + "5.2", + ) return thai_synonyms() diff --git a/pythainlp/phayathaibert/core.py b/pythainlp/phayathaibert/core.py index f3563a45e..acd5d39cb 100644 --- a/pythainlp/phayathaibert/core.py +++ b/pythainlp/phayathaibert/core.py @@ -394,7 +394,7 @@ def get_ner( if pos: warnings.warn( "This model doesn't support output \ - postag and It doesn't output the postag." + postag and it doesn't output the postag." ) sample_output = [] diff --git a/pythainlp/tools/core.py b/pythainlp/tools/core.py index 1c5e5daa2..54396f4a2 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: diff --git a/pythainlp/util/thaiwordcheck.py b/pythainlp/util/thaiwordcheck.py index 0fe3f296b..a67071e70 100644 --- a/pythainlp/util/thaiwordcheck.py +++ b/pythainlp/util/thaiwordcheck.py @@ -1,15 +1,17 @@ # -*- coding: utf-8 -*- # SPDX-FileCopyrightText: 2016-2024 PyThaiNLP Project # SPDX-License-Identifier: Apache-2.0 -import warnings +from pythainlp.tools import warn_deprecation + def is_native_thai(word: str) -> bool: - warnings.warn( - """ - pythainlp.util.is_native_thai is rename as \ - pythainlp.morpheme.is_native_thai. - This function will remove in PyThaiNLP 5.1. - """, DeprecationWarning) + warn_deprecation( + "pythainlp.util.is_native_thai", + "pythainlp.morpheme.is_native_thai", + "5.0", + "5.1", + ) + from pythainlp.morpheme import is_native_thai as check return check(word) diff --git a/pythainlp/wangchanberta/core.py b/pythainlp/wangchanberta/core.py index afae29c40..4227be8fa 100644 --- a/pythainlp/wangchanberta/core.py +++ b/pythainlp/wangchanberta/core.py @@ -182,7 +182,7 @@ def get_ner( if pos: warnings.warn( - "This model doesn't support output postag and It doesn't output the postag." + "This model doesn't support output postag and it doesn't output the postag." ) words_token = word_tokenize(text.replace(" ", "<_>")) inputs = self.tokenizer(