Bugfix/fix mypy errors#13
Merged
Merged
Conversation
Add read_image_rgb helper that raises FileNotFoundError when cv2.imread returns None, and count queries during iteration in top_k_accuracy instead of calling len() on an Iterable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add missing '| None' to parameters defaulting to None, declare attribute placeholders with their real types, and correct the similarity_func type: it returns a similarity matrix (np.ndarray), not a float. ImageEncoderBase now requires a feature extractor and defaults similarity_func to cosine_similarity instead of None. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Import FeatureExtractorBase and SimilarityMetric from their defining module, annotate the _pca/_clustering_model placeholders, and replace property fget/fset class access with a protected _set_clustering_model method that subclass setters call directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add per-module ignore_missing_imports overrides for third-party libraries that ship without type stubs or a py.typed marker. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Use non-inplace division in RootSIFT since in-place true division is not defined for the integer dtypes cv2 may return. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Wrap untyped sklearn results in np.asarray, type the Lambda extractor's callable precisely, validate the submodule returned by getattr, and convert scipy .mat labels to int explicitly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Annotate setup_logging, _set_clustering_model, _register_hook, download_oxford_flowers_data and the SIFT/RootSIFT constructors, and replace torch's untyped private Module._get_name() with type(...).__name__. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Annotate all remaining functions: typed decorator pattern for _check_output_shape and _tupleize_first_arg, an Encoder protocol for eval functions, property getter/setter annotations, and **kwargs types. similarity_score now honestly returns the np.ndarray similarity matrix it always produced at runtime. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Type list_conv_layers as returning Conv2d layers so out_channels is an int instead of the Tensor | Module union from Module.__getattr__. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Remove no-op super().__call__ invocations of the abstract base method from the feature extractors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Parameterize the bare generic types: list[Any] for the heatmap matrix and Dataset[tuple[np.ndarray, int, str]] for OxfordFlowerDataset. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Annotate the hook buffer as Tensor | None, widen the VLAD descriptor vector annotation, and use a separate variable for the spatial coordinates array. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to eliminate current mypy failures by tightening type annotations across feature extractors, encoders, evaluation utilities, and dataset loading, while also reducing third-party stub noise via mypy import overrides.
Changes:
- Added/strengthened type annotations and Protocols (e.g.,
Encoderineval.py, typed weights in encoders, stricter base class signatures). - Centralized image reading into
read_image_rgb()and refactored dataset/encoding-map generation to use it. - Adjusted similarity APIs to consistently return
np.ndarraysimilarity matrices and updated mypy configuration overrides for missing stubs.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| pyvisim/features/_features.py | Refines feature extractor typing, decorator typing, and DeepConvFeature annotations. |
| pyvisim/eval.py | Introduces an Encoder Protocol and tightens typing in evaluation helpers. |
| pyvisim/encoders/vlad.py | Adds typed weights and adjusts clustering model typing/access. |
| pyvisim/encoders/pipeline.py | Refactors encoding-map generation to use shared image-reading utility and updates similarity typing. |
| pyvisim/encoders/fisher_vector.py | Adds typed weights and adjusts clustering model typing/access. |
| pyvisim/encoders/_base_encoder.py | Tightens base encoder typing (similarity functions, clustering setters) and refactors image loading. |
| pyvisim/datasets/datasets.py | Improves Oxford Flowers dataset typing and uses shared read_image_rgb. |
| pyvisim/_utils.py | Adds read_image_rgb and normalizes return types to np.ndarray. |
| pyvisim/_config.py | Adds concrete types/return annotation to setup_logging. |
| pyvisim/_base_classes.py | Tightens abstract base class signatures/return types. |
| pyproject.toml | Adds mypy overrides to ignore missing imports for select third-party libs. |
Comments suppressed due to low confidence (1)
pyvisim/encoders/pipeline.py:38
Pipeline.__init__assignsself._similarity_funcdirectly, which bypassescheck_desired_output(...)validation/wrapping enforced by thesimilarity_funcsetter. This can reintroduce runtime errors (or incorrect shapes) even though the setter exists for safety.
self._check_valid_encoders(encoders)
self.encoders = encoders
self._similarity_func = similarity_func
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…lass has to implement its own
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR attempts to remove all errors that mypy currently throws,. The goal is to enforce that mypy returns zero error before every PR. These include:
Type annotation and type safety improvements:
Refactoring and code clarity:
Configuration and dependency management:
pyproject.tomlto instruct mypy to ignore missing imports for several third-party libraries that lack type stubs, reducing unnecessary type-checking errors.Dataset class and utility improvements: