applied RUFF C408 rule (unnecessary-collection-call)

Signed-off-by: bigcat88 <bigcat88@icloud.com>
This commit is contained in:
Alexander Piskun 2025-01-02 08:44:11 +02:00 committed by bigcat88
parent 0f11d60afb
commit 8fefe02cd1
No known key found for this signature in database
GPG Key ID: 1F0BF0EC3CF22721
11 changed files with 24 additions and 21 deletions

View File

@ -510,7 +510,7 @@ def get_sorted_list_via_attr(objects: list, attr: str) -> list:
unique_attrs = {} unique_attrs = {}
for o in objects: for o in objects:
val_attr = getattr(o, attr) 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) attr_list.append(o)
if val_attr not in unique_attrs: if val_attr not in unique_attrs:
unique_attrs[val_attr] = attr_list unique_attrs[val_attr] = attr_list

View File

@ -19,7 +19,7 @@ class DiagonalGaussianRegularizer(torch.nn.Module):
yield from () yield from ()
def forward(self, z: torch.Tensor) -> Tuple[torch.Tensor, dict]: def forward(self, z: torch.Tensor) -> Tuple[torch.Tensor, dict]:
log = dict() log = {}
posterior = DiagonalGaussianDistribution(z) posterior = DiagonalGaussianDistribution(z)
if self.sample: if self.sample:
z = posterior.sample() z = posterior.sample()
@ -88,7 +88,7 @@ class AbstractAutoencoder(torch.nn.Module):
def instantiate_optimizer_from_config(self, params, lr, cfg): def instantiate_optimizer_from_config(self, params, lr, cfg):
logging.info(f"loading >>> {cfg['target']} <<< optimizer from config") logging.info(f"loading >>> {cfg['target']} <<< optimizer from config")
return get_obj_from_str(cfg["target"])( 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: def configure_optimizers(self) -> Any:
@ -129,7 +129,7 @@ class AutoencodingEngine(AbstractAutoencoder):
) -> Union[torch.Tensor, Tuple[torch.Tensor, dict]]: ) -> Union[torch.Tensor, Tuple[torch.Tensor, dict]]:
z = self.encoder(x) z = self.encoder(x)
if unregularized: if unregularized:
return z, dict() return z, {}
z, reg_log = self.regularization(z) z, reg_log = self.regularization(z)
if return_reg_log: if return_reg_log:
return z, reg_log return z, reg_log
@ -191,7 +191,7 @@ class AutoencodingEngineLegacy(AutoencodingEngine):
N = x.shape[0] N = x.shape[0]
bs = self.max_batch_size bs = self.max_batch_size
n_batches = int(math.ceil(N / bs)) n_batches = int(math.ceil(N / bs))
z = list() z = []
for i_batch in range(n_batches): for i_batch in range(n_batches):
z_batch = self.encoder(x[i_batch * bs : (i_batch + 1) * bs]) z_batch = self.encoder(x[i_batch * bs : (i_batch + 1) * bs])
z_batch = self.quant_conv(z_batch) z_batch = self.quant_conv(z_batch)
@ -211,7 +211,7 @@ class AutoencodingEngineLegacy(AutoencodingEngine):
N = z.shape[0] N = z.shape[0]
bs = self.max_batch_size bs = self.max_batch_size
n_batches = int(math.ceil(N / bs)) n_batches = int(math.ceil(N / bs))
dec = list() dec = []
for i_batch in range(n_batches): for i_batch in range(n_batches):
dec_batch = self.post_quant_conv(z[i_batch * bs : (i_batch + 1) * bs]) dec_batch = self.post_quant_conv(z[i_batch * bs : (i_batch + 1) * bs])
dec_batch = self.decoder(dec_batch, **decoder_kwargs) dec_batch = self.decoder(dec_batch, **decoder_kwargs)

View File

@ -13,7 +13,7 @@ def log_txt_as_img(wh, xc, size=10):
# wh a tuple of (width, height) # wh a tuple of (width, height)
# xc a list of captions to plot # xc a list of captions to plot
b = len(xc) b = len(xc)
txts = list() txts = []
for bi in range(b): for bi in range(b):
txt = Image.new("RGB", wh, color="white") txt = Image.new("RGB", wh, color="white")
draw = ImageDraw.Draw(txt) draw = ImageDraw.Draw(txt)
@ -77,7 +77,7 @@ def instantiate_from_config(config):
elif config == "__is_unconditional__": elif config == "__is_unconditional__":
return None return None
raise KeyError("Expected key `target` to instantiate.") 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): 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)) raise ValueError("Invalid weight_decay value: {}".format(weight_decay))
if not 0.0 <= ema_decay <= 1.0: if not 0.0 <= ema_decay <= 1.0:
raise ValueError("Invalid ema_decay value: {}".format(ema_decay)) raise ValueError("Invalid ema_decay value: {}".format(ema_decay))
defaults = dict(lr=lr, betas=betas, eps=eps, defaults = {"lr": lr, "betas": betas, "eps": eps,
weight_decay=weight_decay, amsgrad=amsgrad, ema_decay=ema_decay, "weight_decay": weight_decay, "amsgrad": amsgrad, "ema_decay": ema_decay,
ema_power=ema_power, param_names=param_names) "ema_power": ema_power, "param_names": param_names}
super().__init__(params, defaults) super().__init__(params, defaults)
def __setstate__(self, state): def __setstate__(self, state):

View File

@ -185,7 +185,7 @@ def finalize_default_conds(model: 'BaseModel', hooked_to_run: dict[comfy.hooks.H
p = p._replace(mult=mult) p = p._replace(mult=mult)
if p.hooks is not None: if p.hooks is not None:
model.current_patcher.prepare_hook_patches_current_keyframe(timestep, p.hooks, model_options) 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)] hooked_to_run[p.hooks] += [(p, i)]
def calc_cond_batch(model: 'BaseModel', conds: list[list[dict]], x_in: torch.Tensor, timestep, model_options): 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 continue
if p.hooks is not None: if p.hooks is not None:
model.current_patcher.prepare_hook_patches_current_keyframe(timestep, p.hooks, model_options) 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)] hooked_to_run[p.hooks] += [(p, i)]
default_conds.append(default_c) default_conds.append(default_c)

View File

@ -26,7 +26,7 @@ def gen_empty_tokens(special_tokens, length):
class ClipTokenWeightEncoder: class ClipTokenWeightEncoder:
def encode_token_weights(self, token_weight_pairs): def encode_token_weights(self, token_weight_pairs):
to_encode = list() to_encode = []
max_token_len = 0 max_token_len = 0
has_weights = False has_weights = False
for x in token_weight_pairs: for x in token_weight_pairs:

View File

@ -164,7 +164,7 @@ class SaveAudio:
def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
filename_prefix += self.prefix_append filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir) full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir)
results = list() results = []
metadata = {} metadata = {}
if not args.disable_metadata: if not args.disable_metadata:

View File

@ -99,7 +99,7 @@ class SaveAnimatedWEBP:
method = self.methods.get(method) method = self.methods.get(method)
filename_prefix += self.prefix_append 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]) 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 = [] pil_images = []
for image in images: for image in images:
i = 255. * image.cpu().numpy() 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): def save_images(self, images, fps, compress_level, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
filename_prefix += self.prefix_append 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]) 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 = [] pil_images = []
for image in images: for image in images:
i = 255. * image.cpu().numpy() i = 255. * image.cpu().numpy()

View File

@ -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) output = merge_result_data(results, obj)
else: else:
output = [] output = []
ui = dict() ui = {}
if len(uis) > 0: if len(uis) > 0:
ui = {k: [y for x in uis for y in x[k]] for k in uis[0].keys()} ui = {k: [y for x in uis for y in x[k]] for k in uis[0].keys()}
return output, ui, has_subgraph return output, ui, has_subgraph

View File

@ -477,7 +477,7 @@ class SaveLatent:
file = f"{filename}_{counter:05}_.latent" file = f"{filename}_{counter:05}_.latent"
results = list() results = []
results.append({ results.append({
"filename": file, "filename": file,
"subfolder": subfolder, "subfolder": subfolder,
@ -1582,7 +1582,7 @@ class SaveImage:
def save_images(self, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): def save_images(self, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
filename_prefix += self.prefix_append 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]) 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): for (batch_number, image) in enumerate(images):
i = 255. * image.cpu().numpy() i = 255. * image.cpu().numpy()
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))

View File

@ -1,3 +1,5 @@
target-version = "py38"
# Disable all rules by default # Disable all rules by default
lint.ignore = ["ALL"] 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. # 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 # See all rules here: https://docs.astral.sh/ruff/rules/#pyflakes-f
"F", "F",
"C408",
] ]
exclude = ["*.ipynb"] exclude = ["*.ipynb"]

View File

@ -171,7 +171,7 @@ class PromptServer():
max_upload_size = round(args.max_upload_size * 1024 * 1024) max_upload_size = round(args.max_upload_size * 1024 * 1024)
self.app = web.Application(client_max_size=max_upload_size, middlewares=middlewares) self.app = web.Application(client_max_size=max_upload_size, middlewares=middlewares)
self.sockets = dict() self.sockets = {}
self.web_root = ( self.web_root = (
FrontendManager.init_frontend(args.front_end_version) FrontendManager.init_frontend(args.front_end_version)
if args.front_end_root is None if args.front_end_root is None