touketsu.core.urt_method¶
-
@touketsu.core.urt_method¶ Decorate instance methods to temporarily allow attribute creation.
Apply
urt_method()to instance methods to temporarily remove the class restriction during the execution of the instance method. For example, suppose we have a classa_class, wherefrom touketsu import nondynamic, urt_method @nondynamic class a_class: def __init__(self, a = "a"): self.a = a @classmethod def a_class_method(cls): cls.aa = 1000 return cls(a = "A") @urt_method def method_one(self, val): self.b = val def method_two(self): if hasattr(self, "b"): return f"{self.a} UwU {self.b}" return f"{self.a} T^T"
method_oneneeds to be decorated withurt_method()since it will create an instance attributebwhen called. However,method_twodoes not need to be decorated since it is not creating or modifying any instance attributes. Theclassmethod()a_class_methodalso does not need to be decorated sincetouketsurestrictions only apply to class instances, not the classes themselves.- Parameters
meth (function) – An unbound instance method
- Returns
A decorated unbound instance method that allows instance attribute modification and creation during its execution.
- Return type
function