fix: 工程化收敛并移除 ASYNC230/ASYNC240 忽略 (#5729)#8499
Conversation
* test(skills): align sandbox cache tests with readonly behavior * ci(release): enforce core quality gate before publish * ci: enforce locked dependency installs in workflows * security: remove curl-pipe-shell installs * chore: align project python baseline to 3.12 * ci(dashboard): add explicit typecheck gate * chore(pre-commit): align ruff hook version with project * ci(codeql): add javascript-typescript analysis * chore(ruff): defer py312 migration lint rules * fix: resolve ruff violations without new ignores * fix: resolve ASYNC230 and ASYNC240 without ignores * fix(auth): replace utcnow with timezone-aware UTC now * fix: avoid blocking file read in file_to_base64
There was a problem hiding this comment.
Sorry @Lemon-OvO, your pull request is larger than the review limit of 150000 diff characters
There was a problem hiding this comment.
Code Review
This pull request upgrades the codebase to Python 3.12, updates Dockerfile and pre-commit configurations, and migrates various synchronous blocking I/O operations to asynchronous equivalents or asyncio.to_thread wrappers. It also adopts Python 3.12 type parameter syntax and standardizes timeout parameter names to timeout_seconds. The review feedback recommends further optimizing performance and non-blocking behavior by wrapping remaining synchronous calls (such as shutil.copy2, os.remove, and os.makedirs) in asyncio.to_thread, utilizing aiofiles to avoid thread-switching overhead during chunked file downloads, and updating legacy parameter names to match the new timeout_seconds convention.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| config_content = zf.read("config/cmd_config.json") | ||
| # 备份现有配置 | ||
| if os.path.exists(self.config_path): | ||
| if await asyncio.to_thread(os.path.exists, self.config_path): |
| logger.info(f"[EdgeTTS] 返回值(0代表成功): {p.returncode}") | ||
|
|
||
| os.remove(mp3_path) | ||
| if ( |
| if await asyncio.to_thread(os.path.exists, mp3_path): | ||
| os.remove(mp3_path) |
| if await asyncio.to_thread(os.path.exists, mp3_path): | ||
| os.remove(mp3_path) |
| if converted_audio_path and await asyncio.to_thread( | ||
| os.path.exists, converted_audio_path | ||
| ): |
| file_obj = await asyncio.to_thread(Path(path).open, "wb") | ||
| try: |
| input_data = await asyncio.to_thread(Path(silk_path).read_bytes) | ||
| if input_data.startswith(b"\x02"): | ||
| input_data = input_data[1:] | ||
| input_io = BytesIO(input_data) | ||
| output_io = BytesIO() | ||
| pysilk.decode(input_io, output_io, 24000) | ||
| output_io.seek(0) | ||
| with wave.open(output_path, "wb") as wav: | ||
| wav.setnchannels(1) | ||
| wav.setsampwidth(2) | ||
| wav.setframerate(24000) | ||
| wav.writeframes(output_io.read()) |
There was a problem hiding this comment.
在 tencent_silk_to_wav 异步函数中,pysilk.decode 以及 wave.open 写入音频帧都是同步阻塞的 I/O 和 CPU 密集型操作。为了彻底避免阻塞事件循环,建议将整个转换逻辑封装为一个内部同步函数,并通过 asyncio.to_thread 异步执行。
| input_data = await asyncio.to_thread(Path(silk_path).read_bytes) | |
| if input_data.startswith(b"\x02"): | |
| input_data = input_data[1:] | |
| input_io = BytesIO(input_data) | |
| output_io = BytesIO() | |
| pysilk.decode(input_io, output_io, 24000) | |
| output_io.seek(0) | |
| with wave.open(output_path, "wb") as wav: | |
| wav.setnchannels(1) | |
| wav.setsampwidth(2) | |
| wav.setframerate(24000) | |
| wav.writeframes(output_io.read()) | |
| def _sync_silk_to_wav(): | |
| input_data = Path(silk_path).read_bytes() | |
| if input_data.startswith(b"\x02"): | |
| input_data = input_data[1:] | |
| input_io = BytesIO(input_data) | |
| output_io = BytesIO() | |
| pysilk.decode(input_io, output_io, 24000) | |
| output_io.seek(0) | |
| with wave.open(output_path, "wb") as wav: | |
| wav.setnchannels(1) | |
| wav.setsampwidth(2) | |
| wav.setframerate(24000) | |
| wav.writeframes(output_io.read()) | |
| await asyncio.to_thread(_sync_silk_to_wav) |
| return silk_b64, duration # 已是秒 | ||
| finally: | ||
| if os.path.exists(wav_path) and wav_path != audio_path: | ||
| if await asyncio.to_thread(os.path.exists, wav_path) and wav_path != audio_path: |
|
|
||
| # 检查文件是否存在并注册令牌 | ||
| if os.path.exists(logo_file_path): | ||
| if await asyncio.to_thread(os.path.exists, logo_file_path): |
| os.makedirs(local_dir, exist_ok=True) | ||
| with open(local_path, "wb") as f: | ||
| f.write(cast(bytes, content)) | ||
| await asyncio.to_thread(Path(local_path).write_bytes, cast(bytes, content)) |
|
PR 改动太多了,无力审核,关闭。有大的改动请先邮箱告知。 |
test(skills): align sandbox cache tests with readonly behavior
ci(release): enforce core quality gate before publish
ci: enforce locked dependency installs in workflows
security: remove curl-pipe-shell installs
chore: align project python baseline to 3.12
ci(dashboard): add explicit typecheck gate
chore(pre-commit): align ruff hook version with project
ci(codeql): add javascript-typescript analysis
chore(ruff): defer py312 migration lint rules
fix: resolve ruff violations without new ignores
fix: resolve ASYNC230 and ASYNC240 without ignores
fix(auth): replace utcnow with timezone-aware UTC now
fix: avoid blocking file read in file_to_base64
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。