Autogenerated code is too sensitive to small changes

This commit is contained in:
doctorpangloss 2024-06-19 09:42:14 -07:00
parent 6015c4132f
commit 68f410b8da
5 changed files with 62 additions and 32 deletions

View File

@ -878,3 +878,13 @@ init-import=no
# List of qualified module names which can have objects that can redefine # List of qualified module names which can have objects that can redefine
# builtins. # builtins.
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io 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

View File

@ -13,22 +13,19 @@ from comfy.api.shared_imports.schema_imports import * # pyright: ignore [report
class SchemaEnums: class SchemaEnums:
@classmethod
def output(cls) -> typing.Literal["output"]: @schemas.classproperty
def OUTPUT(cls) -> typing.Literal["output"]:
return Schema.validate("output") return Schema.validate("output")
@classmethod @schemas.classproperty
def input(cls) -> typing.Literal["input"]: def INPUT(cls) -> typing.Literal["input"]:
return Schema.validate("input") return Schema.validate("input")
@classmethod @schemas.classproperty
def temp(cls) -> typing.Literal["temp"]: def TEMP(cls) -> typing.Literal["temp"]:
return Schema.validate("temp") return Schema.validate("temp")
OUTPUT = property(output)
INPUT = property(input)
TEMP = property(temp)
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class Schema( class Schema(

View File

@ -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_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_1 import schema as schema_3
from comfy.api.paths.view.get.parameters.parameter_2 import schema as schema_2 from comfy.api.paths.view.get.parameters.parameter_2 import schema as schema_2
Properties = typing.TypedDict(
'Properties',
class Properties(typing.TypedDict): {
filename: typing.Type[schema.Schema] "filename": typing.Type[schema.Schema],
subfolder: typing.Type[schema_2.Schema] "subfolder": typing.Type[schema_2.Schema],
type: typing.Type[schema_3.Schema] "type": typing.Type[schema_3.Schema],
}
class QueryParametersRequiredDictInput(typing.TypedDict): )
filename: str QueryParametersRequiredDictInput = typing.TypedDict(
'QueryParametersRequiredDictInput',
class QueryParametersOptionalDictInput(typing.TypedDict, total=False): {
subfolder: str "filename": str,
type: typing.Literal["output", "input", "temp"] }
)
QueryParametersOptionalDictInput = typing.TypedDict(
'QueryParametersOptionalDictInput',
{
"subfolder": str,
"type": typing.Literal[
"output",
"input",
"temp"
],
},
total=False
)
class QueryParametersDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]): class QueryParametersDict(schemas.immutabledict[str, schemas.OUTPUT_BASE_TYPES]):

View File

@ -14,6 +14,7 @@ import typing_extensions
from .schema import ( from .schema import (
get_class, get_class,
none_type_, none_type_,
classproperty,
Bool, Bool,
FileIO, FileIO,
Schema, Schema,
@ -103,6 +104,7 @@ def raise_if_key_known(
__all__ = [ __all__ = [
'get_class', 'get_class',
'none_type_', 'none_type_',
'classproperty',
'Bool', 'Bool',
'FileIO', 'FileIO',
'Schema', 'Schema',

View File

@ -96,6 +96,17 @@ class FileIO(io.FileIO):
pass 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: class Bool:
_instances: typing.Dict[typing.Tuple[type, bool], Bool] = {} _instances: typing.Dict[typing.Tuple[type, bool], Bool] = {}
""" """
@ -128,17 +139,14 @@ class Bool:
return f'<Bool: True>' return f'<Bool: True>'
return f'<Bool: False>' return f'<Bool: False>'
@classmethod @classproperty
def true(cls): def TRUE(cls):
return cls(True) # type: ignore return cls(True) # type: ignore
@classmethod @classproperty
def false(cls): def FALSE(cls):
return cls(False) # type: ignore return cls(False) # type: ignore
TRUE = property(true)
FALSE = property(false)
@functools.lru_cache() @functools.lru_cache()
def __bool__(self) -> bool: def __bool__(self) -> bool:
for key, instance in self._instances.items(): for key, instance in self._instances.items():
@ -395,11 +403,11 @@ class Schema(typing.Generic[T, U], validation.SchemaValidator, metaclass=Singlet
return used_arg return used_arg
output_cls = type_to_output_cls[arg_type] output_cls = type_to_output_cls[arg_type]
if arg_type is tuple: 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) inst = typing.cast(U, inst)
return inst return inst
assert issubclass(output_cls, validation.immutabledict) 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) inst = typing.cast(T, inst)
return inst return inst