执行摘要
移除测试崩溃计数器的冗余 hasattr 保护
消除死代码,简化测试辅助逻辑。init 已确保属性存在,hasattr 检查不再必要。
简单清理,可安全合并。
无讨论。
消除死代码,简化测试辅助逻辑。init 已确保属性存在,hasattr 检查不再必要。
简单清理,可安全合并。
无讨论。
在 _trigger_crash_for_tests 方法中删除两行:
- if not hasattr(self, "_test_stream_output_count"):
- self._test_stream_output_count = 0
由于 __init__ 已设置为 0,该赋值不再需要。
| 文件 | 模块 | 状态 | 重要度 |
|---|---|---|---|
python/sglang/srt/managers/scheduler_components/output_streamer.py |
调度器 | modified | 4.47 |
python/sglang/srt/managers/scheduler_components/output_streamer.py
core-logic
删除 _trigger_crash_for_tests 中的 hasattr fallback,简化测试崩溃计数器逻辑。
# python/sglang/srt/managers/scheduler_components/output_streamer.py
# __init__ 已经设置了 self._test_stream_output_count = 0,因此 hasattr 检查是冗余的。
def _trigger_crash_for_tests(self, crash_threshold: int):
# Crash trigger: crash after stream_output is called N times
# This is used for testing purposes.
self._test_stream_output_count += 1
if self._test_stream_output_count >= crash_threshold:
raise RuntimeError(
f"Test crash after stream_output called {self._test_stream_output_count} times"
)
当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。
风险极低:属性已在 init 中初始化,删除 hasattr 不会改变行为。
仅影响测试崩溃触发逻辑,无用户可见影响。
当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。
参与讨论