diff --git a/pyproject.toml b/pyproject.toml index ebb62207b..c22f04f28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -414,21 +414,23 @@ 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 = false -disallow_incomplete_defs = false -disallow_untyped_decorators = false +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 show_error_code_links = true show_error_context = true +strict = true strict_bytes = true strict_equality = true strict_equality_for_none = true @@ -436,18 +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 - -# 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]] 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