Fix mutable default argument and unreachable exception handler - #3775
Fix mutable default argument and unreachable exception handler#3775Mr-Neutr0n wants to merge 2 commits into
Conversation
- Replace mutable default list `sampling_boost_models=[]` with `None` in `get_sample_weight()` to avoid the well-known mutable default argument pitfall (gradio_block_arena_anony.py). - Reorder exception handlers in `chat_completion_openai_azure()` so `InvalidRequestError` is caught before its parent `OpenAIError`. The previous ordering made the `InvalidRequestError` handler unreachable dead code (llm_judge/common.py).
The mutable-default fix in the previous commit was a single long line that exceeds black's default 88-char line length, causing the CI's 'black --check .' step to fail. Wrap the function signature across three lines so black is happy without changing behavior. Verified locally with 'black --check .': all 148 files now pass. Signed-off-by: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com>
|
CI failure diagnosed + fixed ( The def get_sample_weight(model, outage_models, sampling_weights, sampling_boost_models=None):That's 88+ characters, which exceeds black's default 88-char line length. Fixed by wrapping the signature across three lines (no behavior change). Verified locally: The pylint step also has dependency issues locally on my machine (the CI's |
|
Quick follow-up: the branch now has the formatting fix pushed ( |
|
Closing this one to tidy up my open pull requests. It's been open around five months with no review activity, and I'd rather withdraw it than leave it sitting in your queue. Nothing needed from you, and no hard feelings at all. If the fix is still wanted, this can be reopened, or I'm happy to redo it properly against current main. Apologies for the noise. |
Summary
fastchat/serve/gradio_block_arena_anony.py: Replace mutable default argumentsampling_boost_models=[]withNoneinget_sample_weight(). Mutable defaults are shared across all calls and can lead to subtle, hard-to-diagnose bugs when the list is mutated.fastchat/llm_judge/common.py: Reorder exception handlers inchat_completion_openai_azure()so thatopenai.error.InvalidRequestErroris caught before its parent classopenai.error.OpenAIError. The previous ordering made theInvalidRequestErrorhandler unreachable dead code, meaning invalid request errors were retried instead of breaking immediately.Test plan
get_sample_weight()still works correctly with and withoutsampling_boost_modelsargumentInvalidRequestErrorbefore the genericOpenAIError