From f39a622ab772000f34f08c1d12872807f8a5dc11 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Wed, 25 Feb 2026 02:09:11 +0000 Subject: [PATCH] fix: use ImportError for import fallback and context managers for file reads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - prompt_expand.py: bare except → except ImportError - wandb.py: 2x open().read() → with open() as f: f.read() --- fastgen/callbacks/wandb.py | 6 ++++-- fastgen/third_party/wan_prompt_expand/prompt_expand.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fastgen/callbacks/wandb.py b/fastgen/callbacks/wandb.py index e6ee396..757e3fa 100644 --- a/fastgen/callbacks/wandb.py +++ b/fastgen/callbacks/wandb.py @@ -91,7 +91,8 @@ def init_wandb(config: BaseConfig): # wandb login wandb_credential = config.log_config.wandb_credential if os.path.isfile(wandb_credential): - os.environ["WANDB_API_KEY"] = open(wandb_credential, encoding="utf-8").read().strip("\n") + with open(wandb_credential, encoding="utf-8") as f: + os.environ["WANDB_API_KEY"] = f.read().strip("\n") logger.info(f"Loading WANDB_API_KEY from {wandb_credential}") wandb_config = config.log_config @@ -101,7 +102,8 @@ def init_wandb(config: BaseConfig): os.makedirs(wandb_config.save_path, exist_ok=True) wandb_id_path = f"{wandb_config.save_path}/wandb_id.txt" if os.path.isfile(wandb_id_path): - wandb_id = open(wandb_id_path, encoding="utf-8").read().strip() + with open(wandb_id_path, encoding="utf-8") as f: + wandb_id = f.read().strip() logger.info(f"Resuming with an existing wandb id: {wandb_id}") else: wandb_id = wandb.util.generate_id() diff --git a/fastgen/third_party/wan_prompt_expand/prompt_expand.py b/fastgen/third_party/wan_prompt_expand/prompt_expand.py index 6a5d601..d95db58 100644 --- a/fastgen/third_party/wan_prompt_expand/prompt_expand.py +++ b/fastgen/third_party/wan_prompt_expand/prompt_expand.py @@ -250,7 +250,7 @@ def __init__(self, model_name=None, device=0, is_vl=False, **kwargs): ) try: from .qwen_vl_utils import process_vision_info - except: + except ImportError: from qwen_vl_utils import process_vision_info self.process_vision_info = process_vision_info min_pixels = 256 * 28 * 28