Skip to content

Bugfix/fix mypy errors#13

Merged
MechaCritter merged 17 commits into
mainfrom
bugfix/fix_mypy_errors
Jun 11, 2026
Merged

Bugfix/fix mypy errors#13
MechaCritter merged 17 commits into
mainfrom
bugfix/fix_mypy_errors

Conversation

@MechaCritter

Copy link
Copy Markdown
Owner

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:

  • Updated pyproject.toml to 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:

  • Improved the Oxford Flower dataset loader to use the new image reading utility and added more precise type annotations for dataset outputs and label loading. [1] [2] [3]

MechaCritter and others added 12 commits June 11, 2026 19:52
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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., Encoder in eval.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.ndarray similarity 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__ assigns self._similarity_func directly, which bypasses check_desired_output(...) validation/wrapping enforced by the similarity_func setter. 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.

Comment thread pyvisim/features/_features.py
Comment thread pyvisim/encoders/_base_encoder.py
Comment thread pyvisim/encoders/_base_encoder.py Outdated
Comment thread pyvisim/encoders/vlad.py
Comment thread pyvisim/encoders/fisher_vector.py
Comment thread pyvisim/eval.py Outdated
Comment thread pyvisim/eval.py
Comment thread pyvisim/eval.py
Comment thread pyvisim/eval.py
@MechaCritter MechaCritter merged commit bcc9a60 into main Jun 11, 2026
3 checks passed
@MechaCritter MechaCritter deleted the bugfix/fix_mypy_errors branch June 11, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants