You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I may have found an issue with FunctionMaker.create(). When you try to pass a string containing a return type annotation, it breaks this function. Consider this example:
fromdecoratorimportFunctionMakerdefadd(a: int, b: int) ->int:
returna+badd2=FunctionMaker.create("add2(a: int, b: int)", "return add(a, b)", evaldict={"add": add}) # No problemassertadd2(6, 8) ==add(6, 8) # add2 does the same as addadd3=FunctionMaker.create("add3(a: int, b: int) -> int", "return add(a, b)", evaldict={"add": add}) # ERROR
I get a message like this:
File "/nfs/iil/proj/dt/prv08/airon/git/socb_client/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3457, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-9-5d5ad6515055>", line 9, in <module>
add3 = FunctionMaker.create("add3(a: int, b: int) -> int", "return add(a, b)", evaldict={"add": add})
File "/nfs/iil/proj/dt/prv08/airon/git/socb_client/venv/lib/python3.9/site-packages/decorator.py", line 222, in create
return self.make(body, evaldict, addsource, **attrs)
File "/nfs/iil/proj/dt/prv08/airon/git/socb_client/venv/lib/python3.9/site-packages/decorator.py", line 184, in make
code = compile(src, filename, 'single')
File "<decorator-gen-123>", line 1
def add3(a: int, b: int) -> in):
^
SyntaxError: invalid syntax
It seems like the code that decomposes the signature at
I think I may have found an issue with
FunctionMaker.create()
. When you try to pass a string containing a return type annotation, it breaks this function. Consider this example:I get a message like this:
It seems like the code that decomposes the signature at
decorator/src/decorator.py
Line 181 in 9cf8151
assumes the end of the signature is always a right parenthesis, which is not the case when we specify a return type annotation.
Then, the code at
decorator/src/decorator.py
Line 195 in 9cf8151
I could fix this issue in my own environment, but the fix is kind of dirty, and has not gone through all your testing, obviously.
The text was updated successfully, but these errors were encountered: