Skip to content

Commit

Permalink
Alias Operation
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Mar 21, 2024
1 parent 6e42774 commit 50bbe4b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/saleyo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from .operation import Post as Post
from .operation import Del as Del
from .operation import ReName as ReName
from .operation import Alias as Alias
from .base.toolchain import ToolChain as ToolChain
from .base.toolchain import Arguments as Arguments
from .base.toolchain import InvokeEvent as InvokeEvent
Expand Down
1 change: 1 addition & 0 deletions src/saleyo/operation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from .intercept import Intercept as Intercept
from .modify import ReName as ReName
from .modify import Del as Del
from .modify import Alias as Alias
from .hook import Pre as Pre
from .hook import Post as Post
15 changes: 15 additions & 0 deletions src/saleyo/operation/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ class Del(MixinOperation[str]):

def mixin(self, target: Type[Any], toolchain: ToolChain = ToolChain()) -> None:
return toolchain.tool_delattr(target, self.argument)


class Alias(MixinOperation[str]):
"""will copy the `argument` to `alias`"""

alias: str

def __init__(self, argument: str, alias: str, level=1) -> None:
super().__init__(argument, level)
self.alias = alias

def mixin(self, target: Type[Any], toolchain: ToolChain = ToolChain()) -> None:
return toolchain.tool_setattr(
target, self.alias, toolchain.tool_getattr(target, self.argument)
)
7 changes: 4 additions & 3 deletions tests/modify_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from saleyo import ReName, GCToolChain
from saleyo import Alias, GCToolChain

ReName("upper", "lower").mixin(str, GCToolChain)
Alias("upper", "do_upper").mixin(str, GCToolChain)

print("Hello Saleyo!".lower())
print("Hello Saleyo!".do_upper())
print("Hello Saleyo!".upper())

0 comments on commit 50bbe4b

Please sign in to comment.