@@ -82,7 +82,7 @@ def __init__(
82
82
)
83
83
84
84
@property
85
- def function (self ) -> types .FunctionType :
85
+ def unwrapped_function (self ) -> types .FunctionType :
86
86
"""
87
87
Return the compiled function object.
88
88
@@ -94,11 +94,33 @@ def function(self) -> types.FunctionType:
94
94
:raise SyntaxError: if the function code has syntax errors (or if
95
95
the function name is not a valid identifier)
96
96
"""
97
- return inspect .unwrap (self .wrapped_function )
97
+ globals_dict = {
98
+ "__builtins__" : globals ()["__builtins__" ],
99
+ "__name__" : "__main__" ,
100
+ "__doc__" : None ,
101
+ "__package__" : None ,
102
+ }
103
+
104
+ if not is_valid_variable_name (self .function_name ):
105
+ raise SyntaxError ("Invalid function name '{}'" .format (self .function_name ))
106
+
107
+ # Optionally one could do a ast.parse here already, to check syntax
108
+ # before execution
109
+ try :
110
+ exec (
111
+ compile (self .full_function_code , __name__ , "exec" , dont_inherit = True ),
112
+ globals_dict ,
113
+ )
114
+ except SyntaxError as exc :
115
+ raise CodeValidationError (
116
+ format_syntax_error_msg (exc ), orig_exc = exc
117
+ ) from exc
118
+
119
+ return globals_dict [self .function_name ]
98
120
99
121
def __call__ (self , * args , ** kwargs ) -> Check .FunOutParamsT :
100
122
"""Calls the wrapped function"""
101
- return self .wrapped_function (* args , ** kwargs )
123
+ return self .function (* args , ** kwargs )
102
124
103
125
def compatible_with_signature (self , parameters : List [str ]) -> str :
104
126
"""
@@ -223,7 +245,7 @@ def get_function_body(function: types.FunctionType) -> str:
223
245
return source
224
246
225
247
@property
226
- def wrapped_function (self ) -> types .FunctionType :
248
+ def function (self ) -> types .FunctionType :
227
249
"""
228
250
Return the compiled function object wrapped by an try-catch block
229
251
raising a `CodeValidationError`.
@@ -236,29 +258,6 @@ def wrapped_function(self) -> types.FunctionType:
236
258
:raise SyntaxError: if the function code has syntax errors (or if
237
259
the function name is not a valid identifier)
238
260
"""
239
- globals_dict = {
240
- "__builtins__" : globals ()["__builtins__" ],
241
- "__name__" : "__main__" ,
242
- "__doc__" : None ,
243
- "__package__" : None ,
244
- }
245
-
246
- if not is_valid_variable_name (self .function_name ):
247
- raise SyntaxError ("Invalid function name '{}'" .format (self .function_name ))
248
-
249
- # Optionally one could do a ast.parse here already, to check syntax
250
- # before execution
251
- try :
252
- exec (
253
- compile (self .full_function_code , __name__ , "exec" , dont_inherit = True ),
254
- globals_dict ,
255
- )
256
- except SyntaxError as exc :
257
- raise CodeValidationError (
258
- format_syntax_error_msg (exc ), orig_exc = exc
259
- ) from exc
260
-
261
- function_object = globals_dict [self .function_name ]
262
261
263
262
def catch_exceptions (func ):
264
263
@wraps (func )
@@ -274,7 +273,7 @@ def wrapper(*args, **kwargs):
274
273
275
274
return wrapper
276
275
277
- return catch_exceptions (function_object )
276
+ return catch_exceptions (self . unwrapped_function )
278
277
279
278
280
279
# Temporary fix until https://github.com/osscar-org/widget-code-input/pull/26
0 commit comments