Skip to content

refactor(speaker-identification-widget): extract __init__ into smaller methods to fix R0915#1536

Merged
raivisdejus merged 6 commits into
chidiwilliams:mainfrom
josiasdev:refactor/remove-code-smell-speaker-widger-extract-init-R0915
Jul 1, 2026
Merged

refactor(speaker-identification-widget): extract __init__ into smaller methods to fix R0915#1536
raivisdejus merged 6 commits into
chidiwilliams:mainfrom
josiasdev:refactor/remove-code-smell-speaker-widger-extract-init-R0915

Conversation

@josiasdev

Copy link
Copy Markdown
Contributor

Why is this change necessary?

The __init__ method of SpeakerIdentificationWidget had 88 statements, far exceeding Pylint's limit of 50 (too-many-statements / R0915). This made the method hard to read, test, and maintain — it was responsible for:

  • Setting up instance variables
  • Creating the entire Step 1 UI (label, identify/cancel buttons, progress bar)
  • Creating the entire Step 2 UI (label, speaker name inputs, play sample button)
  • Creating the save section (merge checkbox, save button)
  • Initializing the audio preview player

Having all this logic in a single method violates the Single Responsibility Principle and hurts maintainability.


How was this tested?

All existing tests were run and passed successfully:

uv run pytest -s -vv --benchmark-skip -k "speaker"
# Result: 13 passed, 1 skipped

The refactoring is purely structural — no behavior was changed.


Notes for the reviewer

The original __init__ was broken down into four private methods, each with a clear responsibility:

  • _create_step_1_group(layout) — builds the "Identify speakers" section (label, buttons, progress bar)
  • _create_step_2_group(layout) — builds the "Name speakers" section (label, speaker input, preview button)
  • _create_save_section(layout) — builds the merge checkbox and save button
  • _setup_audio_player() — initializes the QMediaPlayer and QAudioOutput

The extracted methods follow the existing codebase patterns and are placed right after __init__, before the event handlers. No logic was altered, only relocated.

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.79%. Comparing base (42e4433) to head (acd52f1).

Files with missing lines Patch % Lines
buzz/model_loader.py 61.11% 7 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1536   +/-   ##
=======================================
  Coverage   81.78%   81.79%           
=======================================
  Files         108      108           
  Lines       11581    11599   +18     
=======================================
+ Hits         9472     9487   +15     
- Misses       2109     2112    +3     
Flag Coverage Δ
Linux 81.69% <74.07%> (+<0.01%) ⬆️
macOS 78.28% <40.74%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raivisdejus
raivisdejus enabled auto-merge (squash) July 1, 2026 06:54
@raivisdejus
raivisdejus merged commit f5f67f7 into chidiwilliams:main Jul 1, 2026
15 of 19 checks passed
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