Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse argument assignment order #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pscript/parser2.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,17 +934,17 @@ def parse_FunctionDef(self, node, lambda_=False, asyn=False):
if not node.kwargs_node:
code.append(", '%s'" % func_name or 'anonymous')
code.append(');')
if vararg_code2:
code.append(self.lf(vararg_code2))
# Apply values of positional args
# inside if, because standard arguments are invalid
args_var = 'arguments[0].flx_args'
if len(argnames) > 1:
args_var = self.dummy('args')
code.append(self.lf('%s = arguments[0].flx_args;' % args_var))
for i, name in enumerate(argnames):
for i, name in reversed(list(enumerate(argnames))):
code.append(self.lf('%s = %s[%i];' % (name, args_var, i)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that I don't follow. As far as I can see, the order should not matter, since we do not change arguments[0].flx_args. What am I missing?

Could you add a test for the problem you were having? That would help in understanding this change, and make sure that it's not accidentally broken at a later time :)

Copy link
Contributor Author

@Winand Winand Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@almarklein when you call a function like this one def partial2(a1, a2, *args, **kwargs): your "real" arguments dictionary is in a1 (which is the same with arguments[0]).

The following happens (at least in Chrome):

  1. You extract **kwargs from arguments[0]
  2. You extract and assign positional arguments starting with the 1st one (a1)
  3. So you've just cleared original arguments[0] (a1) by assigning a new value to a1
  4. You cannot access original arguments[0] anymore.

# End if
if vararg_code2:
code.append(self.lf(vararg_code2))
self._indent -= 1
code.append(self.lf('}'))
if vararg_code1:
Expand Down