From 8fefe02cd1f6659d2058c8bf2b614b0c18785f9d Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Thu, 2 Jan 2025 08:44:11 +0200 Subject: [PATCH] applied RUFF C408 rule (unnecessary-collection-call) Signed-off-by: bigcat88 --- comfy/hooks.py | 2 +- comfy/ldm/models/autoencoder.py | 10 +++++----- comfy/ldm/util.py | 10 +++++----- comfy/samplers.py | 4 ++-- comfy/sd1_clip.py | 2 +- comfy_extras/nodes_audio.py | 2 +- comfy_extras/nodes_images.py | 4 ++-- execution.py | 2 +- nodes.py | 4 ++-- ruff.toml | 3 +++ server.py | 2 +- 11 files changed, 24 insertions(+), 21 deletions(-) diff --git a/comfy/hooks.py b/comfy/hooks.py index 79a7090b..6c2435b1 100644 --- a/comfy/hooks.py +++ b/comfy/hooks.py @@ -510,7 +510,7 @@ def get_sorted_list_via_attr(objects: list, attr: str) -> list: unique_attrs = {} for o in objects: val_attr = getattr(o, attr) - attr_list: list = unique_attrs.get(val_attr, list()) + attr_list: list = unique_attrs.get(val_attr, []) attr_list.append(o) if val_attr not in unique_attrs: unique_attrs[val_attr] = attr_list diff --git a/comfy/ldm/models/autoencoder.py b/comfy/ldm/models/autoencoder.py index e6493155..4aef9e89 100644 --- a/comfy/ldm/models/autoencoder.py +++ b/comfy/ldm/models/autoencoder.py @@ -19,7 +19,7 @@ class DiagonalGaussianRegularizer(torch.nn.Module): yield from () def forward(self, z: torch.Tensor) -> Tuple[torch.Tensor, dict]: - log = dict() + log = {} posterior = DiagonalGaussianDistribution(z) if self.sample: z = posterior.sample() @@ -88,7 +88,7 @@ class AbstractAutoencoder(torch.nn.Module): def instantiate_optimizer_from_config(self, params, lr, cfg): logging.info(f"loading >>> {cfg['target']} <<< optimizer from config") return get_obj_from_str(cfg["target"])( - params, lr=lr, **cfg.get("params", dict()) + params, lr=lr, **cfg.get("params", {}) ) def configure_optimizers(self) -> Any: @@ -129,7 +129,7 @@ class AutoencodingEngine(AbstractAutoencoder): ) -> Union[torch.Tensor, Tuple[torch.Tensor, dict]]: z = self.encoder(x) if unregularized: - return z, dict() + return z, {} z, reg_log = self.regularization(z) if return_reg_log: return z, reg_log @@ -191,7 +191,7 @@ class AutoencodingEngineLegacy(AutoencodingEngine): N = x.shape[0] bs = self.max_batch_size n_batches = int(math.ceil(N / bs)) - z = list() + z = [] for i_batch in range(n_batches): z_batch = self.encoder(x[i_batch * bs : (i_batch + 1) * bs]) z_batch = self.quant_conv(z_batch) @@ -211,7 +211,7 @@ class AutoencodingEngineLegacy(AutoencodingEngine): N = z.shape[0] bs = self.max_batch_size n_batches = int(math.ceil(N / bs)) - dec = list() + dec = [] for i_batch in range(n_batches): dec_batch = self.post_quant_conv(z[i_batch * bs : (i_batch + 1) * bs]) dec_batch = self.decoder(dec_batch, **decoder_kwargs) diff --git a/comfy/ldm/util.py b/comfy/ldm/util.py index 30b4b472..ebbf59d7 100644 --- a/comfy/ldm/util.py +++ b/comfy/ldm/util.py @@ -13,7 +13,7 @@ def log_txt_as_img(wh, xc, size=10): # wh a tuple of (width, height) # xc a list of captions to plot b = len(xc) - txts = list() + txts = [] for bi in range(b): txt = Image.new("RGB", wh, color="white") draw = ImageDraw.Draw(txt) @@ -77,7 +77,7 @@ def instantiate_from_config(config): elif config == "__is_unconditional__": return None raise KeyError("Expected key `target` to instantiate.") - return get_obj_from_str(config["target"])(**config.get("params", dict())) + return get_obj_from_str(config["target"])(**config.get("params", {})) def get_obj_from_str(string, reload=False): @@ -106,9 +106,9 @@ class AdamWwithEMAandWings(optim.Optimizer): raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if not 0.0 <= ema_decay <= 1.0: raise ValueError("Invalid ema_decay value: {}".format(ema_decay)) - defaults = dict(lr=lr, betas=betas, eps=eps, - weight_decay=weight_decay, amsgrad=amsgrad, ema_decay=ema_decay, - ema_power=ema_power, param_names=param_names) + defaults = {"lr": lr, "betas": betas, "eps": eps, + "weight_decay": weight_decay, "amsgrad": amsgrad, "ema_decay": ema_decay, + "ema_power": ema_power, "param_names": param_names} super().__init__(params, defaults) def __setstate__(self, state): diff --git a/comfy/samplers.py b/comfy/samplers.py index 89464a42..2b0b933e 100644 --- a/comfy/samplers.py +++ b/comfy/samplers.py @@ -185,7 +185,7 @@ def finalize_default_conds(model: 'BaseModel', hooked_to_run: dict[comfy.hooks.H p = p._replace(mult=mult) if p.hooks is not None: model.current_patcher.prepare_hook_patches_current_keyframe(timestep, p.hooks, model_options) - hooked_to_run.setdefault(p.hooks, list()) + hooked_to_run.setdefault(p.hooks, []) hooked_to_run[p.hooks] += [(p, i)] def calc_cond_batch(model: 'BaseModel', conds: list[list[dict]], x_in: torch.Tensor, timestep, model_options): @@ -220,7 +220,7 @@ def _calc_cond_batch(model: 'BaseModel', conds: list[list[dict]], x_in: torch.Te continue if p.hooks is not None: model.current_patcher.prepare_hook_patches_current_keyframe(timestep, p.hooks, model_options) - hooked_to_run.setdefault(p.hooks, list()) + hooked_to_run.setdefault(p.hooks, []) hooked_to_run[p.hooks] += [(p, i)] default_conds.append(default_c) diff --git a/comfy/sd1_clip.py b/comfy/sd1_clip.py index 95d41c30..0923615c 100644 --- a/comfy/sd1_clip.py +++ b/comfy/sd1_clip.py @@ -26,7 +26,7 @@ def gen_empty_tokens(special_tokens, length): class ClipTokenWeightEncoder: def encode_token_weights(self, token_weight_pairs): - to_encode = list() + to_encode = [] max_token_len = 0 has_weights = False for x in token_weight_pairs: diff --git a/comfy_extras/nodes_audio.py b/comfy_extras/nodes_audio.py index 3cb918e0..5bf04abe 100644 --- a/comfy_extras/nodes_audio.py +++ b/comfy_extras/nodes_audio.py @@ -164,7 +164,7 @@ class SaveAudio: def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): filename_prefix += self.prefix_append full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir) - results = list() + results = [] metadata = {} if not args.disable_metadata: diff --git a/comfy_extras/nodes_images.py b/comfy_extras/nodes_images.py index af37666b..85dba641 100644 --- a/comfy_extras/nodes_images.py +++ b/comfy_extras/nodes_images.py @@ -99,7 +99,7 @@ class SaveAnimatedWEBP: method = self.methods.get(method) filename_prefix += self.prefix_append full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0]) - results = list() + results = [] pil_images = [] for image in images: i = 255. * image.cpu().numpy() @@ -160,7 +160,7 @@ class SaveAnimatedPNG: def save_images(self, images, fps, compress_level, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): filename_prefix += self.prefix_append full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0]) - results = list() + results = [] pil_images = [] for image in images: i = 255. * image.cpu().numpy() diff --git a/execution.py b/execution.py index 2c979205..a145350a 100644 --- a/execution.py +++ b/execution.py @@ -232,7 +232,7 @@ def get_output_data(obj, input_data_all, execution_block_cb=None, pre_execute_cb output = merge_result_data(results, obj) else: output = [] - ui = dict() + ui = {} if len(uis) > 0: ui = {k: [y for x in uis for y in x[k]] for k in uis[0].keys()} return output, ui, has_subgraph diff --git a/nodes.py b/nodes.py index 7f9f5aa5..328a156a 100644 --- a/nodes.py +++ b/nodes.py @@ -477,7 +477,7 @@ class SaveLatent: file = f"{filename}_{counter:05}_.latent" - results = list() + results = [] results.append({ "filename": file, "subfolder": subfolder, @@ -1582,7 +1582,7 @@ class SaveImage: def save_images(self, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): filename_prefix += self.prefix_append full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0]) - results = list() + results = [] for (batch_number, image) in enumerate(images): i = 255. * image.cpu().numpy() img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) diff --git a/ruff.toml b/ruff.toml index 660831f2..6b03f21c 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,3 +1,5 @@ +target-version = "py38" + # Disable all rules by default lint.ignore = ["ALL"] @@ -9,6 +11,7 @@ lint.select = [ # The "F" series in Ruff stands for "Pyflakes" rules, which catch various Python syntax errors and undefined names. # See all rules here: https://docs.astral.sh/ruff/rules/#pyflakes-f "F", + "C408", ] exclude = ["*.ipynb"] diff --git a/server.py b/server.py index ceb5e83b..a80be401 100644 --- a/server.py +++ b/server.py @@ -171,7 +171,7 @@ class PromptServer(): max_upload_size = round(args.max_upload_size * 1024 * 1024) self.app = web.Application(client_max_size=max_upload_size, middlewares=middlewares) - self.sockets = dict() + self.sockets = {} self.web_root = ( FrontendManager.init_frontend(args.front_end_version) if args.front_end_root is None