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
In current FunctionMaker.create, if the function to create from is an async function and if the function body contains any occurrence of return, it will blindly replace it with return await. This will raise a SyntaxError in edge cases where return is present not as the keyword return but a substring.
However, this replacement is blind, if a parameter is named like return_value, it will be also replaced as it contains return (like the above example).
Moreover, the following lines can produce similar errors:
return_value = ... A simple assignment statement
"This is a long message containing a return word"
Fix
To fix, we need to match return as a keyword rather than as any substring. A straightforward fix looks like the following (not fully tested):
The text was updated successfully, but these errors were encountered:
pengzhengyi
changed the title
Bug in FunctionMaker.create where SyntaxError is raised because of simple replacing strategyFunctionMaker.create raises unexpected SyntaxError when return is present as substring for async function
Feb 9, 2022
About
In current
FunctionMaker.create
, if the function to create from is an async function and if the function body contains any occurrence of return, it will blindly replace it withreturn await
. This will raise a SyntaxError in edge cases wherereturn
is present not as the keyword return but a substring.Reproduce
Error Message
Analysis
FunctionMaker.create
has the following:However, this replacement is blind, if a parameter is named like
return_value
, it will be also replaced as it containsreturn
(like the above example).Moreover, the following lines can produce similar errors:
return_value = ...
A simple assignment statement"This is a long message containing a return word"
Fix
To fix, we need to match return as a keyword rather than as any substring. A straightforward fix looks like the following (not fully tested):
The text was updated successfully, but these errors were encountered: