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 = {}
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

View File

@ -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)

View File

@ -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):

View File

@ -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)

View File

@ -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:

View File

@ -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:

View File

@ -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()

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)
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

View File

@ -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))

View File

@ -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"]

View File

@ -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