Skip to content

Commit

Permalink
feat: support funix_class
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Nov 28, 2023
1 parent cf83083 commit 693b310
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/funix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# ---- Exports ----
# ---- Decorators ----
funix = decorator.funix
funix_class = decorator.funix_class
# ---- Decorators ----

Limiter = decorator.Limiter
Expand Down
18 changes: 17 additions & 1 deletion backend/funix/decorator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
from enum import Enum, auto
from functools import wraps
from importlib import import_module
from inspect import Parameter, Signature, getsource, isgeneratorfunction, signature
from inspect import (
Parameter,
Signature,
getsource,
isgeneratorfunction,
signature,
ismethod,
)
from json import dumps, loads
from secrets import token_hex
from traceback import format_exc
Expand Down Expand Up @@ -1910,3 +1917,12 @@ def wrapped_function(**wrapped_function_kwargs):
return function

return decorator


def funix_class(inited_class):
for class_function in dir(inited_class):
if not class_function.startswith("_"):
function = getattr(inited_class, class_function)
print(class_function, function)
if ismethod(function):
funix()(function)
15 changes: 15 additions & 0 deletions examples/class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from funix import funix_class


class A:
def __init__(self):
self.a = 1

def abc(self, b: int, c: int) -> None:
self.a = b + c

def b(self) -> int:
return self.a


funix_class(A())

0 comments on commit 693b310

Please sign in to comment.