Skip to content

Commit

Permalink
fix: custom class error
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Feb 28, 2024
1 parent fac9783 commit 9d7dad2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions backend/funix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def get_path_difference(base_dir: str, target_dir: str) -> str | None:

return ".".join(path_diff)

def getsourcefile_safe(obj: Any) -> str | None:
try:
if isclass(obj):
return getsourcefile(obj.__init__)
return getsourcefile(obj)
except:
return None


def handle_module(
module: Any,
Expand All @@ -92,9 +100,9 @@ def handle_module(
is_func = isfunction(module_member)
is_cls = isclass(module_member)
if is_func or is_cls:
if getsourcefile(module_member) != module.__file__:
if getsourcefile_safe(module_member) != module.__file__:
continue
in_funix = decorator.object_is_handled(id(module_member))
in_funix = decorator.object_is_handled(id(module_member)) or id(module_member) in hint.custom_cls_ids
if in_funix:
continue
use_func = funix if is_func else funix_class
Expand Down
5 changes: 5 additions & 0 deletions backend/funix/hint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ class DecoratedFunctionListItem(TypedDict):
# ---- Decorator ----


custom_cls_ids: list[int] = []


def new_funix_type_with_config_func(
widget: str, config_func: Optional[callable] = None
) -> callable:
Expand All @@ -430,6 +433,7 @@ def decorator(cls) -> Any:
Returns:
Any: The decorated class or getting the new funix type function.
"""
custom_cls_ids.append(id(cls))
if config_func is None:
cls.__funix__ = True
cls.__funix_widget__ = widget
Expand Down Expand Up @@ -489,6 +493,7 @@ def new_funix_type(widget: NewFunixWidgetType) -> callable:
"""

def decorator(cls) -> Any:
custom_cls_ids.append(id(cls))
cls.__funix__ = True
cls.__funix_widget__ = widget["name"]
cls.__funix_base__ = cls.__base__
Expand Down

0 comments on commit 9d7dad2

Please sign in to comment.