diff --git a/src/saleyo/mixin.py b/src/saleyo/mixin.py index fc2a810..5388f17 100644 --- a/src/saleyo/mixin.py +++ b/src/saleyo/mixin.py @@ -20,7 +20,7 @@ class Mixin: def __init__( self, - target: IterableOrSingle, + target: IterableOrSingle[Type[Any]], toolchain: ToolChain = ToolChain(), reverse_level: bool = False, ) -> None: @@ -120,9 +120,11 @@ def apply_from_class(self, mixin: T) -> T: member.mixin(target=target, toolchain=self.toolchain) return mixin - def apply_from_operations(self, operations: Iterable[MixinOperation]) -> None: + def apply_from_operations( + self, operations: IterableOrSingle[MixinOperation] + ) -> None: """ - Use operations from a `Iterable[MixinOperation]` and apply to target. + Use operations from a `IterableOrSingle[MixinOperation]` and apply to target. Always used to mixin class manually. @@ -133,7 +135,7 @@ def apply_from_operations(self, operations: Iterable[MixinOperation]) -> None: mixin.apply_from_operations([op1, op2]) ``` """ - for operation in operations: + for operation in operations if operations is Iterable else [operations]: for target in self.target: operation.mixin(target=target, toolchain=self.toolchain) diff --git a/tests/gc_test.py b/tests/gc_test.py index d8e6529..a244f24 100644 --- a/tests/gc_test.py +++ b/tests/gc_test.py @@ -4,9 +4,10 @@ @Mixin(target=str, toolchain=GCToolChain) class MixinStr: @Pre.configure(target_name="format") - def pre_format(self, *args) -> Arguments[...]: + def pre_format(self, *args, **kwargs) -> Arguments[...]: print(f"input args: {args}") - return Arguments(self, "python") + print(f"input kwargs: {kwargs}") + return Arguments(self, *args, **kwargs) -print("hello world {}".format("saleyo")) +print("hello world {},{}".format("saleyo", "some")) diff --git a/tests/modify_test.py b/tests/modify_test.py index 4de6e2a..139c9c6 100644 --- a/tests/modify_test.py +++ b/tests/modify_test.py @@ -1,6 +1,8 @@ -from saleyo import Alias, GCToolChain +from saleyo import Alias, GCToolChain, Mixin -Alias("upper", "do_upper").mixin(str, GCToolChain) +alias = Alias("upper", "do_upper") + +Mixin(str, GCToolChain).apply_from_operations(alias) print("Hello Saleyo!".do_upper()) print("Hello Saleyo!".upper())