-
Notifications
You must be signed in to change notification settings - Fork 188
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
Correct handling of walrus operator in function args #417
Conversation
Looks good to me, and I verified locally that it resolves the issue from usort. Before fix:
With fix:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the comment, LGTM.
# "key := value" assignment; positional | ||
if equal.string == ":=": | ||
val = convert_namedexpr_test(config, children) | ||
assert isinstance(val, WithLeadingWhitespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use assert since it's noop in optimized mode. Let's just use if condition and raise when it returns unexpected result.
assert isinstance(val, WithLeadingWhitespace) | |
if isinstance(val, WithLeadingWhitespace): | |
return Arg(value=val.value) | |
else: | |
raise Exception("...") |
Previous behavior treated it as identical to equal, making a kwarg; it should instead be a positional arg. Includes several tests to make sure that whitespace handling is correct. Fixes Instagram#416
Summary
Previous behavior treated it as identical to equal, making a kwarg; it should
instead be a positional arg. Includes several tests to make sure that
whitespace handling is correct.
Fixes #416
Test Plan
Includes new tests that were failing before. I had some trouble ensuring the whitespace ended up in the right spot during development, so this includes a few probably unnecessary tests out of a general distrust that I did it right.