Skip to content

Commit

Permalink
Provide get_function command
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Mar 16, 2024
1 parent e96f1a4 commit ca4233b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion change_log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Version 2.6.0 (3/16/2024)
* Allow unit_test to be used as a context manager
* Various documentation improvements
* Improved table output on terminal
*
* Provide Sandbox command get_function to wrap a function with call

Version 2.5.9 (8/21/2023)
-------------------------
Expand Down
9 changes: 9 additions & 0 deletions pedal/sandbox/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,15 @@ def get_module(module_name, report=MAIN_REPORT):
raise ValueError(f"Unknown Sandbox Module: `{module_name}`")


def get_function(function_name, report=MAIN_REPORT):
"""
Creates an executable function from the given name, based on the
students' namespace. This will be executed using the call method.
"""
sandbox: Sandbox = report[TOOL_NAME]['sandbox']
return sandbox.get_function(function_name)


def get_python_errors(report=MAIN_REPORT):
"""
Retrieves any runtime or syntax errors from the report.
Expand Down
8 changes: 8 additions & 0 deletions pedal/sandbox/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,14 @@ def var(self):
"""
return {k: SandboxVariable(k, v) for k, v in self.data.items()}

def get_function(self, by_name):
"""
Creates an executable function from the given name, based
on the student's namespace. This will be executed using the call
method.
"""
return lambda *args, **kwargs: self.call(by_name, *args, **kwargs)

def __getitem__(self, item):
value, exception = None, None
try:
Expand Down

0 comments on commit ca4233b

Please sign in to comment.