-
Notifications
You must be signed in to change notification settings - Fork 0
Mixin &
H2Sxxa edited this page Jul 31, 2023
·
1 revision
Don't support At
from Remilia.mixin import Mixin,OverWrite
class Demo:
def hello(self,x:int):
print(x)
@Mixin(Demo)
class MixinDemo:
@OverWrite.withValue(method="hello")
def rehello(self,x:int):
print(x+1)
Demo().hello(1)
>>> 2from Remilia.mixin import Mixin,Accessor
class Demo:
__x=1
try:
print(Demo().__x)
except Exception as e:
print(e)
@Mixin(Demo)
class MixinDemo:
@Accessor.withValue(method="__x")
def x():...
print(Demo().__x)
>>> 'Demo' object has no attribute '__x'
>>> 1based on CodeOperator,not supported builtin method, although can open gc
support At.INSERT,At.HEAD,At.END
EnumCOChar
from Remilia.mixin import Mixin,Inject,At
class Demo:
def hello(self):
pass
@Mixin(Demo)
class MixinDemo:
@Inject.withValue(method="hello",at=At.HEAD)
def hello():
print("hello world")
Demo().hello()
>>>hello worldinsertline -> popline
if without insertline , it will redirect to At.HEAD
from Remilia.mixin import Mixin,Inject,At
class Demo:
def hello(self):
print("demo is here")
@Mixin(Demo)
class MixinDemo:
@Inject.withValue(method="hello",at=At.INSERT,insertline=1,poplines=[2])
def hello():
print("hello world")
Demo().hello()
>>> hello worldsupport At.INVOKE,At.RETURN
from typing import Any
from Remilia.mixin import Mixin,Glue,CallableArgs,At
class Demo:
def hello(self,x:int):
print(x)
@Mixin(Demo)
class MixinDemo:
@Glue.withValue(method="hello",at=At.INVOKE)
def inhello(self,x) -> CallableArgs:
return CallableArgs(self,x+100)
@Glue.withValue(method="hello",at=At.RETURN)
def rehello(self,result) -> Any:
return "result: %s" % result
print(Demo().hello(1))
>>> 101
>>> result: None