P2 §5.3: 4 处单点 importlib.import_module → 静态 from import
把单次调用 douyin_screenshot_manager 的 importlib 改为 from-import: - douyin/core/douyin_flow_control.py - douyin/core/underlying_operations.py - douyin/fudai/core/fudai_debug_utils.py - douyin/stage/douyin_stage.py douyin_screenshot_manager 只引用 douyin.core.path_config,与上述 4 个文件 无循环依赖,可以安全静态化。bin/run_cli.py 的 importlib 是有意为之 (绕过 package __init__ 遮蔽),保留。 收益: - 可读性 + IDE 跳转/类型提示 - 每次调用省去 ~100µs 的 import_module 开销 回归:140 .py 编译通过;4 处 importlib 残留全清; test_filter_logging / check_web_gui_config_sync 通过; douyin_screenshot_manager 仍可正常加载。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
0700a378ec
commit
4f147d214e
4 files changed
+4
-16
No files matched your search
@@ -311,11 +311,7 @@ def find_and_open_fudai_detail(
|
||||
# 同步保存一个福袋图标的完整调试截图(确保无论检测路径如何都能保存)
|
||||
try:
|
||||
from PIL import Image # type: ignore[import]
|
||||
import importlib
|
||||
|
||||
douyin_screenshot_manager = importlib.import_module(
|
||||
"douyin.handlers.douyin_screenshot_manager"
|
||||
)
|
||||
from douyin.handlers import douyin_screenshot_manager
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
if os.path.exists(screenshot_path):
|
||||
|
||||
@@ -252,11 +252,8 @@ class underlying_operations:
|
||||
|
||||
# OCR图片文件:按分类组织到子目录
|
||||
try:
|
||||
import importlib
|
||||
from douyin.handlers import douyin_screenshot_manager
|
||||
|
||||
douyin_screenshot_manager = importlib.import_module(
|
||||
"douyin.handlers.douyin_screenshot_manager"
|
||||
)
|
||||
category = douyin_screenshot_manager.get_category_for_picname(picname)
|
||||
except Exception:
|
||||
category = "others"
|
||||
|
||||
@@ -156,8 +156,7 @@ def save_full_screenshot_with_ocr_region(
|
||||
}
|
||||
|
||||
try:
|
||||
import importlib
|
||||
douyin_screenshot_manager = importlib.import_module("douyin.handlers.douyin_screenshot_manager")
|
||||
from douyin.handlers import douyin_screenshot_manager
|
||||
except Exception as e:
|
||||
log_debug_error(
|
||||
analyser,
|
||||
|
||||
@@ -1046,11 +1046,7 @@ def diagnose_stage_from_current_screen(analyser, trigger_reason="unknown"): # t
|
||||
y_pianyi = int(getattr(analyser, "y_pianyi", 0) or 0)
|
||||
# 保存完整截图并标注OCR区域
|
||||
try:
|
||||
import importlib
|
||||
|
||||
douyin_screenshot_manager = importlib.import_module(
|
||||
"douyin.handlers.douyin_screenshot_manager"
|
||||
)
|
||||
from douyin.handlers import douyin_screenshot_manager
|
||||
from douyin.core import path_config
|
||||
import os
|
||||
from PIL import Image
|
||||
|
||||
Reference in new issue
Block a user