-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functools wraps to inspect decorators #1171
base: main
Are you sure you want to change the base?
Conversation
Edit: The issue described in this comment is resolved as of 52183a8 Details
@jjallaire i'm not sure the best way to proceed here. My requirement is to have a way to access the task type hints so that I can dynamically instantiate tasks from config files. The solution I've tried here seems to break some of your tests. For some reason the "return" property of the annotations dict gets deleted when I apply I also tried explicitly adding the return type to the diff --git a/src/inspect_ai/_eval/registry.py b/src/inspect_ai/_eval/registry.py
index 4fb00d65..13d9a13a 100644
--- a/src/inspect_ai/_eval/registry.py
+++ b/src/inspect_ai/_eval/registry.py
@@ -156,6 +156,11 @@ def task(*args: Any, name: str | None = None, **attribs: Any) -> Any:
# Return the task instance
return task_instance
+ wrapper.__annotations__ = {
+ **task_type.__annotations__,
+ 'return': Task
+ }
+
# Register the task and return the wrapper
return task_register(
task=cast(TaskType, wrapper), name=task_name, attribs=attribs, params=params
k=cast(TaskType, wrapper), name=task_name, attribs=attribs, params=params
) I think there's 2 things we could do:
diff --git a/src/inspect_ai/_eval/registry.py b/src/inspect_ai/_eval/registry.py
index 4fb00d65..cf1ded4e 100644
--- a/src/inspect_ai/_eval/registry.py
+++ b/src/inspect_ai/_eval/registry.py
@@ -156,6 +156,8 @@ def task(*args: Any, name: str | None = None, **attribs: Any) -> Any:
# Return the task instance
return task_instance
+ wrapper.__wrapped__ = task_type
+
# Register the task and return the wrapper
return task_register(
task=cast(TaskType, wrapper), name=task_name, attribs=attribs, params=params Then from my code I could call Let me know what you think is best. |
This PR contains:
What is the current behavior? (You can also link to an open issue here)
It's not possible to get type hints for Inspect decorated tasks. Example:
Output:
What is the new behavior?
Type hints are preserved. Behaviour of the above test script afterwards.
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
No
Other information: