|
7 | 7 | from typing import Any, Callable, Dict, List, Optional, Union |
8 | 8 |
|
9 | 9 | from ipywidgets import HTML, Box, HBox, HTMLMath, Layout, VBox, Widget |
| 10 | +from widget_code_input import WidgetCodeInput |
10 | 11 | from widget_code_input.utils import CodeValidationError |
11 | 12 |
|
12 | 13 | from .._utils import Formatter |
@@ -56,7 +57,7 @@ class CodeExercise(VBox, CheckableWidget, AnswerWidget): |
56 | 57 |
|
57 | 58 | def __init__( |
58 | 59 | self, |
59 | | - code: Union[None, CodeInput, types.FunctionType] = None, |
| 60 | + code: Union[None, WidgetCodeInput, types.FunctionType] = None, |
60 | 61 | check_registry: Optional[CheckRegistry] = None, |
61 | 62 | answer_registry: Optional[AnswerRegistry] = None, |
62 | 63 | answer_key: Optional[str] = None, |
@@ -120,6 +121,11 @@ def __init__( |
120 | 121 | # verify if input argument `parameter` is valid |
121 | 122 | if isinstance(code, types.FunctionType): |
122 | 123 | code = CodeInput(function=code) |
| 124 | + elif code is not None and not (isinstance(code, WidgetCodeInput)): |
| 125 | + raise TypeError( |
| 126 | + "For input code expected type None, FunctionType or " |
| 127 | + f"WidgetCodeInput but got {type(code)!r}" |
| 128 | + ) |
123 | 129 |
|
124 | 130 | # check compability between code and parameters, can only be checked if |
125 | 131 | # update_func is not used because we cannot know how the code input is used |
|
0 commit comments