Skip to content

refactor: Remove 'too-many-instance-attributes' (R0902) across multiple modules#2094

Open
thamitaboza wants to merge 1 commit into
mindee:mainfrom
thamitaboza:refactor/remove-code-smell-too-many-instance-attributes
Open

refactor: Remove 'too-many-instance-attributes' (R0902) across multiple modules#2094
thamitaboza wants to merge 1 commit into
mindee:mainfrom
thamitaboza:refactor/remove-code-smell-too-many-instance-attributes

Conversation

@thamitaboza

Copy link
Copy Markdown

Consolidates and reduces the number of instance attributes in constructors to satisfy Pylint limits (< 7) without altering public APIs or execution logic:

  • doctr/models/recognition/sar/pytorch.py (SAR): Grouped config/metadata fields (vocab, exportable, cfg, max_length) into a private self._config dictionary and exposed them via @property getters.
  • doctr/models/recognition/viptr/pytorch.py (VIPTR): Encapsulated primitives (vocab, exportable, cfg, max_length, vocab_size) into self._config using properties for backward compatibility.
  • doctr/utils/metrics.py (OCRMetric): Combined independent scalar accumulators (raw_matches, caseless_matches, anyascii_matches, unicase_matches) into a single structured self.matches dictionary.
  • tests/common/test_utils_metrics.py: Updated unit test assertions to match the new dictionary-based layout for metric evaluation counters.

This change resolves the too-many-statements Pylint warnings by
extracting monolithic blocks into specialized private functions.

The refactoring directly addresses code smells within:
 - doctr/models/detection/differentiable_binarization/base.py
 - doctr/models/layout/lw_detr/pytorch.py
 - doctr/transforms/modules/pytorch.py
 - doctr/utils/metrics.py

Isolating these heavy operations ensures the main execution paths
remain readable and lowers cognitive load without changing behavior.
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.

1 participant