Skip to content

Commit 7201460

Browse files
committed
add raise ValueError when code is wrong parameter type
1 parent e1c26df commit 7201460

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/scwidgets/exercise/_widget_code_exercise.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any, Callable, Dict, List, Optional, Union
88

99
from ipywidgets import HTML, Box, HBox, HTMLMath, Layout, VBox, Widget
10+
from widget_code_input import WidgetCodeInput
1011
from widget_code_input.utils import CodeValidationError
1112

1213
from .._utils import Formatter
@@ -56,7 +57,7 @@ class CodeExercise(VBox, CheckableWidget, AnswerWidget):
5657

5758
def __init__(
5859
self,
59-
code: Union[None, CodeInput, types.FunctionType] = None,
60+
code: Union[None, WidgetCodeInput, types.FunctionType] = None,
6061
check_registry: Optional[CheckRegistry] = None,
6162
answer_registry: Optional[AnswerRegistry] = None,
6263
answer_key: Optional[str] = None,
@@ -120,6 +121,11 @@ def __init__(
120121
# verify if input argument `parameter` is valid
121122
if isinstance(code, types.FunctionType):
122123
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+
)
123129

124130
# check compability between code and parameters, can only be checked if
125131
# update_func is not used because we cannot know how the code input is used

0 commit comments

Comments
 (0)