From 08031128db02f086962c899eee3bb5fa469fc8a9 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Tue, 24 Mar 2026 00:31:18 +0000 Subject: [PATCH 1/3] Remove mypy overrides --- pyproject.toml | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ebb62207b..6490dee4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -421,9 +421,9 @@ skip_install = true # Mypy configuration [tool.mypy] check_untyped_defs = true -disallow_untyped_defs = false -disallow_incomplete_defs = false -disallow_untyped_decorators = false +disallow_untyped_defs = true +disallow_incomplete_defs = true +disallow_untyped_decorators = true pretty = true python_version = "3.9" show_column_numbers = true @@ -440,15 +440,6 @@ warn_unused_configs = true warn_unused_ignores = true warn_unreachable = true -# Per-module options for stricter checking on foundation modules -[[tool.mypy.overrides]] -module = [ - "pythainlp.tools.*", - "pythainlp.cli.*", -] -disallow_untyped_defs = true -disallow_incomplete_defs = true - # Ignore missing imports for optional dependencies [[tool.mypy.overrides]] module = [ From 8f1d7312670b123e199a84e3215636ddf37d4d73 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Tue, 24 Mar 2026 00:41:49 +0000 Subject: [PATCH 2/3] mypy strict = true --- pyproject.toml | 1 + pythainlp/spell/wanchanberta_thai_grammarly.py | 2 +- pythainlp/translate/tokenization_small100.py | 2 +- pythainlp/transliterate/thai2rom.py | 8 ++++---- pythainlp/transliterate/thaig2p.py | 8 ++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6490dee4a..524dfd24b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -429,6 +429,7 @@ python_version = "3.9" show_column_numbers = true show_error_code_links = true show_error_context = true +strict = true strict_bytes = true strict_equality = true strict_equality_for_none = true diff --git a/pythainlp/spell/wanchanberta_thai_grammarly.py b/pythainlp/spell/wanchanberta_thai_grammarly.py index 2846df4e2..5ac7003f1 100644 --- a/pythainlp/spell/wanchanberta_thai_grammarly.py +++ b/pythainlp/spell/wanchanberta_thai_grammarly.py @@ -31,7 +31,7 @@ ) -class BertModel(torch.nn.Module): +class BertModel(torch.nn.Module): # type: ignore[misc] def __init__(self) -> None: super().__init__() self.bert: BertForTokenClassification = ( diff --git a/pythainlp/translate/tokenization_small100.py b/pythainlp/translate/tokenization_small100.py index 6625cf9a5..e40cbd1a4 100644 --- a/pythainlp/translate/tokenization_small100.py +++ b/pythainlp/translate/tokenization_small100.py @@ -65,7 +65,7 @@ # fmt: on -class SMALL100Tokenizer(PreTrainedTokenizer): +class SMALL100Tokenizer(PreTrainedTokenizer): # type: ignore[misc] """Construct an SMALL100 tokenizer. Based on [SentencePiece](https://github.com/google/sentencepiece). This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to this superclass for more information regarding those methods. diff --git a/pythainlp/transliterate/thai2rom.py b/pythainlp/transliterate/thai2rom.py index 39899bb5f..14ce6ebc5 100644 --- a/pythainlp/transliterate/thai2rom.py +++ b/pythainlp/transliterate/thai2rom.py @@ -119,7 +119,7 @@ def romanize(self, text: str) -> str: return "".join(target) -class Encoder(nn.Module): +class Encoder(nn.Module): # type: ignore[misc] hidden_size: int character_embedding: nn.Embedding rnn: nn.LSTM @@ -196,7 +196,7 @@ def init_hidden( return (h_0, c_0) -class Attn(nn.Module): +class Attn(nn.Module): # type: ignore[misc] method: str hidden_size: int attn: nn.Linear @@ -256,7 +256,7 @@ def forward( return F.softmax(attn_energies, 1) -class AttentionDecoder(nn.Module): +class AttentionDecoder(nn.Module): # type: ignore[misc] vocabulary_size: int hidden_size: int character_embedding: nn.Embedding @@ -324,7 +324,7 @@ def forward( return x, hidden[0], attn_weights -class Seq2Seq(nn.Module): +class Seq2Seq(nn.Module): # type: ignore[misc] encoder: Encoder decoder: AttentionDecoder pad_idx: int diff --git a/pythainlp/transliterate/thaig2p.py b/pythainlp/transliterate/thaig2p.py index 7813e801e..f1438198d 100644 --- a/pythainlp/transliterate/thaig2p.py +++ b/pythainlp/transliterate/thaig2p.py @@ -131,7 +131,7 @@ def g2p(self, text: str) -> str: return "".join(target) -class Encoder(nn.Module): +class Encoder(nn.Module): # type: ignore[misc] hidden_size: int character_embedding: nn.Embedding rnn: nn.LSTM @@ -216,7 +216,7 @@ def init_hidden( return (h_0, c_0) -class Attn(nn.Module): +class Attn(nn.Module): # type: ignore[misc] method: str hidden_size: int attn: nn.Linear @@ -278,7 +278,7 @@ def forward( return F.softmax(attn_energies, 1) -class AttentionDecoder(nn.Module): +class AttentionDecoder(nn.Module): # type: ignore[misc] vocabulary_size: int hidden_size: int character_embedding: nn.Embedding @@ -346,7 +346,7 @@ def forward( return x, hidden[0], attn_weights -class Seq2Seq(nn.Module): +class Seq2Seq(nn.Module): # type: ignore[misc] encoder: Encoder decoder: AttentionDecoder pad_idx: int From 7f7d70626212204bfb9c9f8512ff8c0728aedc17 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Tue, 24 Mar 2026 00:44:25 +0000 Subject: [PATCH 3/3] sort config --- pyproject.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 524dfd24b..c22f04f28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -414,16 +414,17 @@ basepython = "pypy3.11" [tool.tox.env.ruff] basepython = "python" -deps = "ruff" commands = [["ruff", "check", "pythainlp"], ["ruff", "format", "--check", "pythainlp"]] +deps = "ruff" skip_install = true # Mypy configuration [tool.mypy] check_untyped_defs = true -disallow_untyped_defs = true disallow_incomplete_defs = true +disallow_subclassing_any = true disallow_untyped_decorators = true +disallow_untyped_defs = true pretty = true python_version = "3.9" show_column_numbers = true @@ -437,9 +438,9 @@ strict_optional = true warn_no_return = true warn_redundant_casts = true warn_return_any = true +warn_unreachable = true warn_unused_configs = true warn_unused_ignores = true -warn_unreachable = true # Ignore missing imports for optional dependencies [[tool.mypy.overrides]]