From 3bf2e5255728f45ec8d98658d914fd2bf6dc2c6b Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Thu, 12 Feb 2026 00:13:22 +0530 Subject: [PATCH 1/2] Fix mutable default argument and unreachable exception handler - 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). --- fastchat/llm_judge/common.py | 6 +++--- fastchat/serve/gradio_block_arena_anony.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fastchat/llm_judge/common.py b/fastchat/llm_judge/common.py index d2640d601..baba272e4 100644 --- a/fastchat/llm_judge/common.py +++ b/fastchat/llm_judge/common.py @@ -454,12 +454,12 @@ def chat_completion_openai_azure(model, conv, temperature, max_tokens, api_dict= ) output = response["choices"][0]["message"]["content"] break - except openai.error.OpenAIError as e: - print(type(e), e) - time.sleep(API_RETRY_SLEEP) except openai.error.InvalidRequestError as e: print(type(e), e) break + except openai.error.OpenAIError as e: + print(type(e), e) + time.sleep(API_RETRY_SLEEP) except KeyError: print(response) break diff --git a/fastchat/serve/gradio_block_arena_anony.py b/fastchat/serve/gradio_block_arena_anony.py index 625c69c44..ecd2d048c 100644 --- a/fastchat/serve/gradio_block_arena_anony.py +++ b/fastchat/serve/gradio_block_arena_anony.py @@ -190,7 +190,9 @@ def share_click(state0, state1, model_selector0, model_selector1, request: gr.Re OUTAGE_MODELS = [] -def get_sample_weight(model, outage_models, sampling_weights, sampling_boost_models=[]): +def get_sample_weight(model, outage_models, sampling_weights, sampling_boost_models=None): + if sampling_boost_models is None: + sampling_boost_models = [] if model in outage_models: return 0 weight = sampling_weights.get(model, 0) From 3475c71567af1c0b2c420d45b188cc34aadde5be Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n Date: Wed, 3 Jun 2026 01:10:23 +0530 Subject: [PATCH 2/2] style: wrap get_sample_weight signature to satisfy black 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> --- fastchat/serve/gradio_block_arena_anony.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastchat/serve/gradio_block_arena_anony.py b/fastchat/serve/gradio_block_arena_anony.py index ecd2d048c..5e8512c9f 100644 --- a/fastchat/serve/gradio_block_arena_anony.py +++ b/fastchat/serve/gradio_block_arena_anony.py @@ -190,7 +190,9 @@ def share_click(state0, state1, model_selector0, model_selector1, request: gr.Re OUTAGE_MODELS = [] -def get_sample_weight(model, outage_models, sampling_weights, sampling_boost_models=None): +def get_sample_weight( + model, outage_models, sampling_weights, sampling_boost_models=None +): if sampling_boost_models is None: sampling_boost_models = [] if model in outage_models: