Skip to content

Commit 5d84607

Browse files
authored
Add type hint for FileLocator (#6968)
* Add type hint for FileLocator * nit
1 parent c1909f3 commit 5d84607

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

comfy/comfy_types/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import torch
22
from typing import Callable, Protocol, TypedDict, Optional, List
3-
from .node_typing import IO, InputTypeDict, ComfyNodeABC, CheckLazyMixin
3+
from .node_typing import IO, InputTypeDict, ComfyNodeABC, CheckLazyMixin, FileLocator
44

55

66
class UnetApplyFunction(Protocol):
@@ -42,4 +42,5 @@ class UnetParams(TypedDict):
4242
InputTypeDict.__name__,
4343
ComfyNodeABC.__name__,
4444
CheckLazyMixin.__name__,
45+
FileLocator.__name__,
4546
]

comfy/comfy_types/node_typing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,14 @@ def check_lazy_status(self, **kwargs) -> list[str]:
295295

296296
need = [name for name in kwargs if kwargs[name] is None]
297297
return need
298+
299+
300+
class FileLocator(TypedDict):
301+
"""Provides type hinting for the file location"""
302+
303+
filename: str
304+
"""The filename of the file."""
305+
subfolder: str
306+
"""The subfolder of the file."""
307+
type: Literal["input", "output", "temp"]
308+
"""The root folder of the file."""

comfy_extras/nodes_audio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import torchaudio
24
import torch
35
import comfy.model_management
@@ -10,6 +12,7 @@
1012
import hashlib
1113
import node_helpers
1214
from comfy.cli_args import args
15+
from comfy.comfy_types import FileLocator
1316

1417
class EmptyLatentAudio:
1518
def __init__(self):
@@ -164,7 +167,7 @@ def INPUT_TYPES(s):
164167
def save_audio(self, audio, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
165168
filename_prefix += self.prefix_append
166169
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir)
167-
results = list()
170+
results: list[FileLocator] = []
168171

169172
metadata = {}
170173
if not args.disable_metadata:

comfy_extras/nodes_images.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import nodes
24
import folder_paths
35
from comfy.cli_args import args
@@ -9,6 +11,8 @@
911
import json
1012
import os
1113

14+
from comfy.comfy_types import FileLocator
15+
1216
MAX_RESOLUTION = nodes.MAX_RESOLUTION
1317

1418
class ImageCrop:
@@ -99,7 +103,7 @@ def save_images(self, images, fps, filename_prefix, lossless, quality, method, n
99103
method = self.methods.get(method)
100104
filename_prefix += self.prefix_append
101105
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])
102-
results = list()
106+
results: list[FileLocator] = []
103107
pil_images = []
104108
for image in images:
105109
i = 255. * image.cpu().numpy()

comfy_extras/nodes_video.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from __future__ import annotations
2+
13
import os
24
import av
35
import torch
46
import folder_paths
57
import json
68
from fractions import Fraction
9+
from comfy.comfy_types import FileLocator
710

811

912
class SaveWEBM:
@@ -62,7 +65,7 @@ def save_images(self, images, codec, fps, filename_prefix, crf, prompt=None, ext
6265
container.mux(stream.encode())
6366
container.close()
6467

65-
results = [{
68+
results: list[FileLocator] = [{
6669
"filename": file,
6770
"subfolder": subfolder,
6871
"type": self.type

nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import comfy.sd
2626
import comfy.utils
2727
import comfy.controlnet
28-
from comfy.comfy_types import IO, ComfyNodeABC, InputTypeDict
28+
from comfy.comfy_types import IO, ComfyNodeABC, InputTypeDict, FileLocator
2929

3030
import comfy.clip_vision
3131

@@ -479,7 +479,7 @@ def save(self, samples, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=No
479479

480480
file = f"{filename}_{counter:05}_.latent"
481481

482-
results = list()
482+
results: list[FileLocator] = []
483483
results.append({
484484
"filename": file,
485485
"subfolder": subfolder,

0 commit comments

Comments
 (0)