File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ def set_result(x: object):
84
84
var_context : dict [str , object ] = {
85
85
"__file__" : file_path ,
86
86
display_decorator_func_name : _display_decorator_function_def ,
87
+ "input" : InputNotImportedShim (),
87
88
}
88
89
89
90
# Execute each top-level node in the AST
@@ -144,3 +145,16 @@ def reset_top_level_recall_context_manager() -> None:
144
145
145
146
def get_top_level_recall_context_manager () -> RecallContextManager [Tag ]:
146
147
return _top_level_recall_context_manager
148
+
149
+
150
+ class InputNotImportedShim :
151
+ # This is a dummy class that is used to provide a helpful error message when the
152
+ # user tries to access `input.x` but forgot to import `input`. If they do that, then
153
+ # it would get the builtin `input` function, and print an unhelpful error message:
154
+ # RuntimeError: 'builtin_function_or_method' object has no attribute 'x'
155
+ # This class provides an error message that is more helpful.
156
+ def __getattr__ (self , name : str ):
157
+ raise AttributeError (
158
+ "Tried to access `input`, but it was not imported. "
159
+ "Perhaps you need `from shiny.express import input`?"
160
+ )
You can’t perform that action at this time.
0 commit comments