From 939bb813f1c0ace959b62f20bb2da47190c4e211 Mon Sep 17 00:00:00 2001 From: Evan Spearman Date: Mon, 2 Sep 2024 12:24:25 -0500 Subject: [PATCH] fix: Fixed the plugin not being loadable in Python versions earlier than 3.10 --- src/comfymath/convert.py | 12 ++++++------ src/comfymath/number.py | 15 +++++++-------- src/comfymath/types.py | 16 ++++++++++++++++ src/comfymath/vec.py | 7 +++---- 4 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 src/comfymath/types.py diff --git a/src/comfymath/convert.py b/src/comfymath/convert.py index 2dc9c80..045caaf 100644 --- a/src/comfymath/convert.py +++ b/src/comfymath/convert.py @@ -1,7 +1,7 @@ from typing import Any, Mapping -from .vec import Vec2, VEC2_ZERO, Vec3, VEC3_ZERO, Vec4, VEC4_ZERO -from .number import number +from .vec import VEC2_ZERO, VEC3_ZERO, VEC4_ZERO +from .types import Number, Vec2, Vec3, Vec4 class BoolToInt: @@ -65,7 +65,7 @@ class IntToNumber: FUNCTION = "op" CATEGORY = "math/conversion" - def op(self, a: int) -> tuple[number]: + def op(self, a: int) -> tuple[Number]: return (a,) @@ -78,7 +78,7 @@ class NumberToInt: FUNCTION = "op" CATEGORY = "math/conversion" - def op(self, a: number) -> tuple[int]: + def op(self, a: Number) -> tuple[int]: return (int(a),) @@ -91,7 +91,7 @@ class FloatToNumber: FUNCTION = "op" CATEGORY = "math/conversion" - def op(self, a: float) -> tuple[number]: + def op(self, a: float) -> tuple[Number]: return (a,) @@ -104,7 +104,7 @@ class NumberToFloat: FUNCTION = "op" CATEGORY = "math/conversion" - def op(self, a: number) -> tuple[float]: + def op(self, a: Number) -> tuple[float]: return (float(a),) diff --git a/src/comfymath/number.py b/src/comfymath/number.py index aa7cf29..d2d3868 100644 --- a/src/comfymath/number.py +++ b/src/comfymath/number.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Any, Callable, Mapping, TypeAlias +from typing import Any, Callable, Mapping from .float import ( FLOAT_UNARY_OPERATIONS, @@ -7,11 +7,10 @@ from .float import ( FLOAT_BINARY_OPERATIONS, FLOAT_BINARY_CONDITIONS, ) +from .types import Number DEFAULT_NUMBER = ("NUMBER", {"default": 0.0}) -number: TypeAlias = int | float - class NumberUnaryOperation: @classmethod @@ -27,7 +26,7 @@ class NumberUnaryOperation: FUNCTION = "op" CATEGORY = "math/number" - def op(self, op: str, a: number) -> tuple[float]: + def op(self, op: str, a: Number) -> tuple[float]: return (FLOAT_UNARY_OPERATIONS[op](float(a)),) @@ -43,9 +42,9 @@ class NumberUnaryCondition: RETURN_TYPES = ("BOOL",) FUNCTION = "op" - CATEGORY = "math/number" + CATEGORY = "math/Number" - def op(self, op: str, a: number) -> tuple[bool]: + def op(self, op: str, a: Number) -> tuple[bool]: return (FLOAT_UNARY_CONDITIONS[op](float(a)),) @@ -64,7 +63,7 @@ class NumberBinaryOperation: FUNCTION = "op" CATEGORY = "math/number" - def op(self, op: str, a: number, b: number) -> tuple[float]: + def op(self, op: str, a: Number, b: Number) -> tuple[float]: return (FLOAT_BINARY_OPERATIONS[op](float(a), float(b)),) @@ -83,7 +82,7 @@ class NumberBinaryCondition: FUNCTION = "op" CATEGORY = "math/float" - def op(self, op: str, a: number, b: number) -> tuple[bool]: + def op(self, op: str, a: Number, b: Number) -> tuple[bool]: return (FLOAT_BINARY_CONDITIONS[op](float(a), float(b)),) diff --git a/src/comfymath/types.py b/src/comfymath/types.py new file mode 100644 index 0000000..7ef1218 --- /dev/null +++ b/src/comfymath/types.py @@ -0,0 +1,16 @@ +import sys + +if sys.version_info[1] < 10: + from typing import Tuple, Union + + Number = Union[int, float] + Vec2 = Tuple[float, float] + Vec3 = Tuple[float, float, float] + Vec4 = Tuple[float, float, float, float] +else: + from typing import TypeAlias + + Number: TypeAlias = int | float + Vec2: TypeAlias = tuple[float, float] + Vec3: TypeAlias = tuple[float, float, float] + Vec4: TypeAlias = tuple[float, float, float, float] diff --git a/src/comfymath/vec.py b/src/comfymath/vec.py index d45a797..0b7180f 100644 --- a/src/comfymath/vec.py +++ b/src/comfymath/vec.py @@ -1,16 +1,15 @@ import numpy -from typing import Any, Callable, Mapping, TypeAlias +from typing import Any, Callable, Mapping + +from .types import Vec2, Vec3, Vec4 -Vec2: TypeAlias = tuple[float, float] VEC2_ZERO = (0.0, 0.0) DEFAULT_VEC2 = ("VEC2", {"default": VEC2_ZERO}) -Vec3: TypeAlias = tuple[float, float, float] VEC3_ZERO = (0.0, 0.0, 0.0) DEFAULT_VEC3 = ("VEC3", {"default": VEC3_ZERO}) -Vec4: TypeAlias = tuple[float, float, float, float] VEC4_ZERO = (0.0, 0.0, 0.0, 0.0) DEFAULT_VEC4 = ("VEC4", {"default": VEC4_ZERO})