Skip to content

Commit f9da915

Browse files
committed
Activate TC rules
1 parent c230255 commit f9da915

116 files changed

Lines changed: 1072 additions & 499 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/source/conf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55

66
# -- Project information -----------------------------------------------------
77
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8+
from __future__ import annotations
9+
810
import os
911
import sys
1012
from importlib.metadata import version
1113
from pathlib import Path
12-
13-
from sphinx.application import Sphinx
14+
from typing import TYPE_CHECKING
1415

1516
conf_dir = os.path.dirname(os.path.abspath(__file__)) # noqa: PTH100, PTH120
1617

1718
sys.path.insert(0, conf_dir)
1819

20+
1921
from docs_utils.skip_members import skip_member # noqa: E402
2022
from docs_utils.tutorials import generate_tutorial_links_for_notebook_creation # noqa: E402
2123
from docs_utils.versions_generator import generate_versions_json # noqa: E402
2224

25+
if TYPE_CHECKING:
26+
from sphinx.application import Sphinx
27+
2328
project = "AutoIntent"
2429
copyright = "2025, DeepPavlov"
2530
author = "DeepPavlov"

docs/source/docs_utils/notebook.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
from __future__ import annotations
2+
13
import abc
24
import re
3-
from typing import ClassVar, Literal
5+
from typing import TYPE_CHECKING, ClassVar, Literal
46

5-
import nbformat
67
from jupytext import jupytext
78
from pydantic import BaseModel
89

10+
if TYPE_CHECKING:
11+
import nbformat
12+
913

1014
class ReplacePattern(BaseModel, abc.ABC):
1115
"""

docs/source/docs_utils/skip_members.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from typing import Any
1+
from __future__ import annotations
22

3-
from sphinx.application import Sphinx
4-
from sphinx.ext.autodoc import Options
3+
from typing import TYPE_CHECKING, Any
4+
5+
if TYPE_CHECKING:
6+
from sphinx.application import Sphinx
7+
from sphinx.ext.autodoc import Options
58

69

710
def skip_member(app: Sphinx, what: str, name: str, obj: Any, skip: bool, options: Options) -> bool | None: # noqa: ANN401, ARG001

docs/source/docs_utils/versions_generator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
from __future__ import annotations
2+
13
import json
24
import logging
35
import os
46
import re
57
import subprocess
6-
from pathlib import Path
8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from pathlib import Path
712

813
logging.basicConfig(level=logging.INFO)
914
logger = logging.getLogger(__name__)

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ ignore = [
158158
"RUF001", # ambiguous unicode character
159159
"PLC0415", # import outside top-level
160160
]
161+
future-annotations = true # For TC rules
161162

162163
[tool.ruff.lint.per-file-ignores]
163164
"__init__.py" = ["F401", "D104"]
@@ -176,6 +177,12 @@ max-args = 10
176177
[tool.ruff.lint.pydocstyle]
177178
convention = "google"
178179

180+
[tool.ruff.lint.flake8-type-checking]
181+
strict = true
182+
183+
[tool.ruff.lint.flake8-unused-arguments]
184+
ignore-variadic-names = true
185+
179186
[tool.pytest.ini_options]
180187
minversion = "8.0"
181188
testpaths = [

src/autointent/_callbacks/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Base class for reporters (W&B, TensorBoard, etc)."""
2+
from __future__ import annotations
23

34
from abc import ABC, abstractmethod
4-
from pathlib import Path
5-
from typing import Any
5+
from typing import TYPE_CHECKING, Any
6+
7+
if TYPE_CHECKING:
8+
from pathlib import Path
69

710

811
class OptimizerCallback(ABC):

src/autointent/_callbacks/callback_handler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
from pathlib import Path
2-
from typing import Any
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Any
34

45
from autointent._callbacks.base import OptimizerCallback
56

7+
if TYPE_CHECKING:
8+
from pathlib import Path
9+
610

711
class CallbackHandler(OptimizerCallback):
812
"""Internal class that just calls the list of callbacks in order."""

src/autointent/_callbacks/emissions_tracker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
"""Emissions tracking functionality for monitoring energy consumption and carbon emissions."""
2+
from __future__ import annotations
23

34
import json
45
import logging
5-
from pathlib import Path
6-
from typing import Any
6+
from typing import TYPE_CHECKING, Any
77

88
from autointent._callbacks import OptimizerCallback
99

10+
if TYPE_CHECKING:
11+
from pathlib import Path
12+
1013
logger = logging.getLogger(__name__)
1114

1215

src/autointent/_callbacks/wandb.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
from __future__ import annotations
2+
13
import logging
24
import os
3-
from pathlib import Path
4-
from typing import Any
5+
from typing import TYPE_CHECKING, Any
56

67
from autointent._callbacks.base import OptimizerCallback
78

9+
if TYPE_CHECKING:
10+
from pathlib import Path
11+
812
logger = logging.getLogger(__name__)
913

1014

src/autointent/_dataset/_dataset.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
"""Defines the Dataset class and related utilities for handling datasets."""
2+
from __future__ import annotations
23

34
import json
45
import logging
56
from collections import defaultdict
67
from functools import cached_property
78
from pathlib import Path
8-
from typing import Any, TypedDict
9+
from typing import TYPE_CHECKING, Any, TypedDict
910

1011
from datasets import Dataset as HFDataset
1112
from datasets import Sequence, get_dataset_config_names, load_dataset
1213

13-
from autointent.custom_types import LabelWithOOS, Split
14-
from autointent.schemas import Intent, Tag
14+
from autointent.custom_types import Split
15+
from autointent.schemas import Tag
16+
17+
if TYPE_CHECKING:
18+
from autointent.custom_types import LabelWithOOS
19+
from autointent.schemas import Intent
1520

1621
logger = logging.getLogger(__name__)
1722

@@ -72,7 +77,7 @@ def n_classes(self) -> int:
7277
return len(self.intents)
7378

7479
@classmethod
75-
def from_dict(cls, mapping: dict[str, Any]) -> "Dataset":
80+
def from_dict(cls, mapping: dict[str, Any]) -> Dataset:
7681
"""Creates a dataset from a dictionary mapping.
7782
7883
Args:
@@ -83,7 +88,7 @@ def from_dict(cls, mapping: dict[str, Any]) -> "Dataset":
8388
return DictReader().read(mapping)
8489

8590
@classmethod
86-
def from_json(cls, filepath: str | Path) -> "Dataset":
91+
def from_json(cls, filepath: str | Path) -> Dataset:
8792
"""Loads a dataset from a JSON file.
8893
8994
Args:
@@ -96,7 +101,7 @@ def from_json(cls, filepath: str | Path) -> "Dataset":
96101
@classmethod
97102
def from_hub(
98103
cls, repo_name: str, data_split: str = "default", intent_subset_name: str = Split.INTENTS
99-
) -> "Dataset":
104+
) -> Dataset:
100105
"""Loads a dataset from the Hugging Face Hub.
101106
102107
Args:
@@ -113,7 +118,7 @@ def from_hub(
113118

114119
return DictReader().read(mapping)
115120

116-
def to_multilabel(self) -> "Dataset":
121+
def to_multilabel(self) -> Dataset:
117122
"""Converts dataset labels to multilabel format."""
118123
for split_name, split in self.items():
119124
self[split_name] = split.map(self._to_multilabel)

0 commit comments

Comments
 (0)