Skip to content

Commit

Permalink
Merge pull request #952 from jimkring/patch-2
Browse files Browse the repository at this point in the history
Fix for cases where source code is not available (e.g. compiled executable)
  • Loading branch information
zzstoatzz authored Jul 22, 2024
2 parents 12f99cd + 8ac33ca commit 1af8e9c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/marvin/utilities/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PythonFunction(BaseModel):
return_annotation: Optional[Any] = Field(
None, description="Return annotation of the function."
)
source_code: str = Field(description="Source code of the function")
source_code: Optional[str] = Field(None, description="Source code of the function")
bound_parameters: dict[str, Any] = Field(
{}, description="Parameters bound with values"
)
Expand Down Expand Up @@ -86,7 +86,15 @@ def from_function(cls, func: Callable, **kwargs) -> "PythonFunction":
)
for name, param in sig.parameters.items()
]
source_code = inspect.getsource(func).strip()

try:
source_code = inspect.getsource(func).strip()
except OSError as e:
error_message = str(e)
if "source code" in error_message:
source_code = None
else:
raise

function_dict = {
"function": func,
Expand Down

0 comments on commit 1af8e9c

Please sign in to comment.