diff --git a/.pylintrc b/.pylintrc index 378e4393b..384c56f2b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -878,3 +878,13 @@ init-import=no # List of qualified module names which can have objects that can redefine # builtins. redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io + +# Disable specific messages for specific files +[file:paths/view/get/query_parameters.py] +disable=duplicate-bases + +[file:paths/view/get/parameters/parameter_1/schema.py] +disable=no-self-argument + +[file:schemas/schema.py] +disable=no-self-argument,bad-super-call diff --git a/comfy/api/paths/view/get/parameters/parameter_1/schema.py b/comfy/api/paths/view/get/parameters/parameter_1/schema.py index df880cbb0..e406907e0 100644 --- a/comfy/api/paths/view/get/parameters/parameter_1/schema.py +++ b/comfy/api/paths/view/get/parameters/parameter_1/schema.py @@ -13,22 +13,19 @@ from comfy.api.shared_imports.schema_imports import * # pyright: ignore [report class SchemaEnums: - @classmethod - def output(cls) -> typing.Literal["output"]: + + @schemas.classproperty + def OUTPUT(cls) -> typing.Literal["output"]: return Schema.validate("output") - @classmethod - def input(cls) -> typing.Literal["input"]: + @schemas.classproperty + def INPUT(cls) -> typing.Literal["input"]: return Schema.validate("input") - @classmethod - def temp(cls) -> typing.Literal["temp"]: + @schemas.classproperty + def TEMP(cls) -> typing.Literal["temp"]: return Schema.validate("temp") - OUTPUT = property(output) - INPUT = property(input) - TEMP = property(temp) - @dataclasses.dataclass(frozen=True) class Schema( diff --git a/comfy/api/paths/view/get/query_parameters.py b/comfy/api/paths/view/get/query_parameters.py index c636e27c3..8d1afb1ee 100644 --- a/comfy/api/paths/view/get/query_parameters.py +++ b/comfy/api/paths/view/get/query_parameters.py @@ -15,19 +15,32 @@ AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema from comfy.api.paths.view.get.parameters.parameter_0 import schema from comfy.api.paths.view.get.parameters.parameter_1 import schema as schema_3 from comfy.api.paths.view.get.parameters.parameter_2 import schema as schema_2 - - -class Properties(typing.TypedDict): - filename: typing.Type[schema.Schema] - subfolder: typing.Type[schema_2.Schema] - type: typing.Type[schema_3.Schema] - -class QueryParametersRequiredDictInput(typing.TypedDict): - filename: str - -class QueryParametersOptionalDictInput(typing.TypedDict, total=False): - subfolder: str - type: typing.Literal["output", "input", "temp"] +Properties = typing.TypedDict( + 'Properties', + { + "filename": typing.Type[schema.Schema], + "subfolder": typing.Type[schema_2.Schema], + "type": typing.Type[schema_3.Schema], + } +) +QueryParametersRequiredDictInput = typing.TypedDict( + 'QueryParametersRequiredDictInput', + { + "filename": str, + } +) +QueryParametersOptionalDictInput = typing.TypedDict( + 'QueryParametersOptionalDictInput', + { + "subfolder": str, + "type": typing.Literal[ + "output", + "input", + "temp" + ], + }, + total=False +) class QueryParametersDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]): diff --git a/comfy/api/schemas/__init__.py b/comfy/api/schemas/__init__.py index 887fd7859..1ea0c6bd4 100644 --- a/comfy/api/schemas/__init__.py +++ b/comfy/api/schemas/__init__.py @@ -14,6 +14,7 @@ import typing_extensions from .schema import ( get_class, none_type_, + classproperty, Bool, FileIO, Schema, @@ -103,6 +104,7 @@ def raise_if_key_known( __all__ = [ 'get_class', 'none_type_', + 'classproperty', 'Bool', 'FileIO', 'Schema', diff --git a/comfy/api/schemas/schema.py b/comfy/api/schemas/schema.py index 71872da90..1118f40e1 100644 --- a/comfy/api/schemas/schema.py +++ b/comfy/api/schemas/schema.py @@ -96,6 +96,17 @@ class FileIO(io.FileIO): pass +class classproperty(typing.Generic[W]): + def __init__(self, method: typing.Callable[..., W]): + self.__method = method + functools.update_wrapper(self, method) # type: ignore + + def __get__(self, obj, cls=None) -> W: + if cls is None: + cls = type(obj) + return self.__method(cls) + + class Bool: _instances: typing.Dict[typing.Tuple[type, bool], Bool] = {} """ @@ -128,16 +139,13 @@ class Bool: return f'' return f'' - @classmethod - def true(cls): + @classproperty + def TRUE(cls): return cls(True) # type: ignore - @classmethod - def false(cls): + @classproperty + def FALSE(cls): return cls(False) # type: ignore - - TRUE = property(true) - FALSE = property(false) @functools.lru_cache() def __bool__(self) -> bool: @@ -395,11 +403,11 @@ class Schema(typing.Generic[T, U], validation.SchemaValidator, metaclass=Singlet return used_arg output_cls = type_to_output_cls[arg_type] if arg_type is tuple: - inst = tuple.__new__(output_cls, used_arg) # type: ignore + inst = super(output_cls, output_cls).__new__(output_cls, used_arg) # type: ignore inst = typing.cast(U, inst) return inst assert issubclass(output_cls, validation.immutabledict) - inst = validation.immutabledict.__new__(output_cls, used_arg) # type: ignore + inst = super(output_cls, output_cls).__new__(output_cls, used_arg) # type: ignore inst = typing.cast(T, inst) return inst