Skip to content

Commit b804d41

Browse files
committed
Use warn_deprecated
1 parent a31f117 commit b804d41

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

pythainlp/cls/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
pythainlp.cls
66
Depreciated. Use pythainlp.classify instead.
77
"""
8-
import warnings
98

109
__all__ = ["GzipModel"]
1110

1211
from pythainlp.classify.param_free import GzipModel
12+
from pythainlp.tools import warn_deprecation
1313

14-
warnings.warn(
15-
"Deprecated: Use pythainlp.classify instead.", DeprecationWarning
16-
)
14+
warn_deprecation("pythainlp.cls", "pythainlp.classify", "5.1", "5.2")

pythainlp/corpus/common.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
]
2525

2626
from typing import FrozenSet, List, Union
27-
import warnings
2827

2928
from pythainlp.corpus import get_corpus, get_corpus_as_is, get_corpus_path
29+
from pythainlp.tools import warn_deprecation
3030

3131
_THAI_COUNTRIES: FrozenSet[str] = frozenset()
3232
_THAI_COUNTRIES_FILENAME = "countries_th.txt"
@@ -56,9 +56,9 @@
5656

5757
_THAI_ORST_WORDS: FrozenSet[str] = frozenset()
5858

59-
_THAI_DICT = {}
60-
_THAI_WSD_DICT = {}
61-
_THAI_SYNONYMS = {}
59+
_THAI_DICT: dict[str, list] = {}
60+
_THAI_WSD_DICT: dict[str, list] = {}
61+
_THAI_SYNONYMS: dict[str, list] = {}
6262

6363

6464
def countries() -> FrozenSet[str]:
@@ -336,7 +336,12 @@ def thai_synonyms() -> dict:
336336

337337

338338
def thai_synonym() -> dict:
339-
warnings.warn("Deprecated: Use thai_synonyms() instead.", DeprecationWarning)
339+
warn_deprecation(
340+
"pythainlp.corpus.thai_synonym",
341+
"pythainlp.corpus.thai_synonyms",
342+
"5.1",
343+
"5.2",
344+
)
340345
return thai_synonyms()
341346

342347

pythainlp/phayathaibert/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def get_ner(
394394
if pos:
395395
warnings.warn(
396396
"This model doesn't support output \
397-
postag and It doesn't output the postag."
397+
postag and it doesn't output the postag."
398398
)
399399

400400
sample_output = []

pythainlp/tools/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def warn_deprecation(
1919
2020
:param str deprecated_func: Name of the deprecated function.
2121
:param str replacing_func: Name of the function to use instead (optional).
22-
:param str deprecated_version: PyThaiNLP version in which the function will be deprecated (optional).
23-
:param str removal_version: PyThaiNLP version in which the function will be removed (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).
2424
"""
2525
message = f"The '{deprecated_func}' function is deprecated"
2626
if deprecated_version:

pythainlp/util/thaiwordcheck.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# -*- coding: utf-8 -*-
22
# SPDX-FileCopyrightText: 2016-2024 PyThaiNLP Project
33
# SPDX-License-Identifier: Apache-2.0
4-
import warnings
4+
from pythainlp.tools import warn_deprecation
5+
56

67
def is_native_thai(word: str) -> bool:
7-
warnings.warn(
8-
"""
9-
pythainlp.util.is_native_thai is rename as \
10-
pythainlp.morpheme.is_native_thai.
11-
This function will remove in PyThaiNLP 5.1.
12-
""", DeprecationWarning)
8+
warn_deprecation(
9+
"pythainlp.util.is_native_thai",
10+
"pythainlp.morpheme.is_native_thai",
11+
"5.0",
12+
"5.1",
13+
)
14+
1315
from pythainlp.morpheme import is_native_thai as check
1416

1517
return check(word)

pythainlp/wangchanberta/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def get_ner(
182182

183183
if pos:
184184
warnings.warn(
185-
"This model doesn't support output postag and It doesn't output the postag."
185+
"This model doesn't support output postag and it doesn't output the postag."
186186
)
187187
words_token = word_tokenize(text.replace(" ", "<_>"))
188188
inputs = self.tokenizer(

0 commit comments

Comments
 (0)