Skip to content

Commit

Permalink
Use warn_deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
bact committed Dec 13, 2024
1 parent a31f117 commit b804d41
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
6 changes: 2 additions & 4 deletions pythainlp/cls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
15 changes: 10 additions & 5 deletions pythainlp/corpus/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion pythainlp/phayathaibert/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
4 changes: 2 additions & 2 deletions pythainlp/tools/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions pythainlp/util/thaiwordcheck.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion pythainlp/wangchanberta/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b804d41

Please sign in to comment.