fix(python-tests): UnboundLocalError instead of the intended ValueError in test_fast_clustering - #3944
Conversation
test_cluster_speaker_embeddings names its extractor config
`extractor_config`, because plain `config` is reused further down for the
FastClusteringConfig. The validation error still interpolates `{config}`,
which at that point is a local that has not been assigned yet, so a model
file that fails to validate raises
UnboundLocalError: cannot access local variable 'config' where it is
not associated with a value
instead of the intended message. Interpolate `extractor_config`, matching
the six sibling call sites (test_speaker_recognition.py and the
speaker-identification examples), which all name the local `config`.
Signed-off-by: Tai An <antai12232931@outlook.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change corrects the invalid extractor-config error message in the fast clustering test. The message now references ChangesExtractor validation
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to This test-only fix reports the invalid extractor configuration correctly and restores the intended ValueError behavior. No merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
csukuangfj
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
The bug
TestFastClustering.test_cluster_speaker_embeddingsnames its extractor configextractor_config, because plainconfigis reused ~20 lines further down for theFastClusteringConfig. The validation error, however, still interpolates{config}:configis a local of this method (bound at line 150), so at line 131 it is unbound. When the extractor config fails to validate — a corrupt or incompatible.onnx, which is exactly what this branch exists to report — the test dies withinstead of the intended message, and the actual config never gets printed.
python -m pyflakeson master flags it:The fix
Interpolate
extractor_config. This is the only place in the Python tree where the validated local and the interpolated name disagree — the six sibling call sites all name the localconfigand print that same local:sherpa-onnx/python/tests/test_speaker_recognition.pypython-api-examples/speaker-identification.pypython-api-examples/speaker-identification-with-vad.pypython-api-examples/speaker-identification-with-vad-dynamic.pypython-api-examples/speaker-identification-with-vad-non-streaming-asr.pypython-api-examples/speaker-identification-with-vad-non-streaming-asr-alsa.pySo this looks like the copy that renamed the local but not the message.
Verification
The test's real method was extracted with
astand run against a stub whoseSpeakerEmbeddingExtractorConfig.validate()returnsFalse(nosherpa_onnxbuild needed), with the wave/model fixture files created so the early-return guards don't fire:The happy path is untouched — this only changes which name the error message reads.
🤖 Generated with Claude Code
Summary by CodeRabbit