-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task_with function for creating task variants (#1099)
* task_with implementation * proper handling of name * consolidate task member assignment logic * require keyword args for task_with * update changelog * mypy fix * correct import for override
- Loading branch information
Showing
7 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .task import Task, TaskInfo, PreviousTask, Tasks # noqa: I001, F401 | ||
from .task import Task, TaskInfo, PreviousTask, Tasks, task_with # noqa: I001, F401 | ||
from .epochs import Epochs | ||
|
||
__all__ = ["Epochs", "Task", "TaskInfo", "PreviousTask", "Tasks"] | ||
__all__ = ["Epochs", "Task", "TaskInfo", "PreviousTask", "Tasks", "task_with"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Sentinel class used until PEP 0661 is accepted | ||
from typing import Literal | ||
|
||
from typing_extensions import override | ||
|
||
|
||
class NotGiven: | ||
"""A sentinel singleton class used to distinguish omitted keyword arguments from those passed in with the value None (which may have different behavior).""" | ||
|
||
def __bool__(self) -> Literal[False]: | ||
return False | ||
|
||
@override | ||
def __repr__(self) -> str: | ||
return "NOT_GIVEN" | ||
|
||
|
||
NOT_GIVEN = NotGiven() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from test_helpers.tasks import minimal_task | ||
|
||
from inspect_ai import task_with | ||
|
||
|
||
def test_task_with_add_options(): | ||
task = task_with(minimal_task(), time_limit=30) | ||
assert task.time_limit == 30 | ||
assert task.metadata is not None | ||
|
||
|
||
def test_task_with_remove_options(): | ||
task = task_with( | ||
minimal_task(), | ||
scorer=None, | ||
) | ||
assert task.scorer is None | ||
assert task.metadata is not None | ||
|
||
|
||
def test_task_with_edit_options(): | ||
task = task_with( | ||
minimal_task(), | ||
metadata={"foo": "bar"}, | ||
) | ||
assert task.metadata == {"foo": "bar"} | ||
|
||
|
||
def test_task_with_name_option(): | ||
task = task_with(minimal_task(), name="changed") | ||
assert task.name == "changed" |