Skip to content

Commit

Permalink
get name from descriptor func
Browse files Browse the repository at this point in the history
  • Loading branch information
ttumiel committed Oct 12, 2023
1 parent 4500b3e commit 211c50e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chat2func/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def __init__(
self.descriptions = descriptions
self.full_docstring = full_docstring
self._cached_schema = None
self.name = function.__name__
self.name = getattr(function, "__name__", None)
if self.name is None and hasattr(function, "__func__"):
self.name = getattr(function.__func__, "__name__", None)

update_wrapper(self, function)

def __get__(self, obj, objtype=None):
Expand Down Expand Up @@ -179,7 +182,7 @@ def test(a: int) -> bool:
```
"""
assert not hasattr(function, "json"), "Function already has a json attribute."
assert callable(function) or isinstance(function, classmethod), "`function` must be callable"
assert callable(function) or hasattr(function, "__get__"), "`function` must be callable"

if function is None:
return partial(JsonSchema, descriptions=descriptions, full_docstring=full_docstring)
Expand Down

0 comments on commit 211c50e

Please sign in to comment.