From d0f0b84c2f8b831ad5333b4a1217de537708d08f Mon Sep 17 00:00:00 2001 From: felix Date: Sat, 16 Nov 2024 18:49:00 +0100 Subject: [PATCH] mypy fixes --- .pre-commit-config.yaml | 2 +- doctr/models/kie_predictor/pytorch.py | 4 ++-- doctr/models/kie_predictor/tensorflow.py | 2 +- doctr/models/predictor/pytorch.py | 4 ++-- doctr/models/predictor/tensorflow.py | 4 ++-- doctr/models/recognition/predictor/pytorch.py | 2 +- pyproject.toml | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bbbdbdf2b1..5b283e9a6a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - id: no-commit-to-branch args: ['--branch', 'main'] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.7.4 hooks: - id: ruff args: [ --fix ] diff --git a/doctr/models/kie_predictor/pytorch.py b/doctr/models/kie_predictor/pytorch.py index 344d882113..61ab910241 100644 --- a/doctr/models/kie_predictor/pytorch.py +++ b/doctr/models/kie_predictor/pytorch.py @@ -51,8 +51,8 @@ def __init__( **kwargs: Any, ) -> None: nn.Module.__init__(self) - self.det_predictor = det_predictor.eval() # type: ignore[attr-defined] - self.reco_predictor = reco_predictor.eval() # type: ignore[attr-defined] + self.det_predictor = det_predictor.eval() + self.reco_predictor = reco_predictor.eval() _KIEPredictor.__init__( self, assume_straight_pages, diff --git a/doctr/models/kie_predictor/tensorflow.py b/doctr/models/kie_predictor/tensorflow.py index fa24ebb40a..3f0d58bbfc 100644 --- a/doctr/models/kie_predictor/tensorflow.py +++ b/doctr/models/kie_predictor/tensorflow.py @@ -102,7 +102,7 @@ def __call__( origin_page_shapes = [page.shape[:2] for page in pages] # Forward again to get predictions on straight pages - loc_preds = self.det_predictor(pages, **kwargs) # type: ignore[assignment] + loc_preds = self.det_predictor(pages, **kwargs) dict_loc_preds: Dict[str, List[np.ndarray]] = invert_data_structure(loc_preds) # type: ignore diff --git a/doctr/models/predictor/pytorch.py b/doctr/models/predictor/pytorch.py index 364db339e8..f9a3d47097 100644 --- a/doctr/models/predictor/pytorch.py +++ b/doctr/models/predictor/pytorch.py @@ -51,8 +51,8 @@ def __init__( **kwargs: Any, ) -> None: nn.Module.__init__(self) - self.det_predictor = det_predictor.eval() # type: ignore[attr-defined] - self.reco_predictor = reco_predictor.eval() # type: ignore[attr-defined] + self.det_predictor = det_predictor.eval() + self.reco_predictor = reco_predictor.eval() _OCRPredictor.__init__( self, assume_straight_pages, diff --git a/doctr/models/predictor/tensorflow.py b/doctr/models/predictor/tensorflow.py index ccf6d441a0..07f12210ce 100644 --- a/doctr/models/predictor/tensorflow.py +++ b/doctr/models/predictor/tensorflow.py @@ -100,12 +100,12 @@ def __call__( origin_page_shapes = [page.shape[:2] for page in pages] # forward again to get predictions on straight pages - loc_preds_dict = self.det_predictor(pages, **kwargs) # type: ignore[assignment] + loc_preds_dict = self.det_predictor(pages, **kwargs) assert all(len(loc_pred) == 1 for loc_pred in loc_preds_dict), ( "Detection Model in ocr_predictor should output only one class" ) - loc_preds: List[np.ndarray] = [list(loc_pred.values())[0] for loc_pred in loc_preds_dict] # type: ignore[union-attr] + loc_preds: List[np.ndarray] = [list(loc_pred.values())[0] for loc_pred in loc_preds_dict] # Detach objectness scores from loc_preds loc_preds, objectness_scores = detach_scores(loc_preds) diff --git a/doctr/models/recognition/predictor/pytorch.py b/doctr/models/recognition/predictor/pytorch.py index d0c3b07601..dc1f644750 100644 --- a/doctr/models/recognition/predictor/pytorch.py +++ b/doctr/models/recognition/predictor/pytorch.py @@ -66,7 +66,7 @@ def forward( crops = new_crops # Resize & batch them - processed_batches = self.pre_processor(crops) + processed_batches = self.pre_processor(crops) # type: ignore[arg-type] # Forward it _params = next(self.model.parameters()) diff --git a/pyproject.toml b/pyproject.toml index 763e966187..db09c839f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -192,7 +192,7 @@ select = [ "E", "W", "F", "I", "N", "Q", "C4", "T10", "LOG", "D101", "D103", "D201","D202","D207","D208","D214","D215","D300","D301","D417", "D419", "D207" # pydocstyle ] -ignore = ["E402", "E203", "F403", "E731", "N812", "N817", "C408"] +ignore = ["E402", "E203", "F403", "E731", "N812", "N817", "C408", "LOG015"] [tool.ruff.lint.isort] known-first-party = ["doctr", "app", "utils"]