Skip to content

Syntaxerror in variable unpacking 487#662

Merged
slozier merged 6 commits intoIronLanguages:masterfrom
hackf5:syntaxerror_in_variable_unpacking_487
Nov 24, 2019
Merged

Syntaxerror in variable unpacking 487#662
slozier merged 6 commits intoIronLanguages:masterfrom
hackf5:syntaxerror_in_variable_unpacking_487

Conversation

@hackf5
Copy link
Copy Markdown
Contributor

@hackf5 hackf5 commented Oct 25, 2019

Resolves #487

as mentioned in the chat I've tried to minimize the changes, however I chose to make a deoptimization in FinishAssignments so that it always allocates a list at the start. imo the improved readability and reduction in cyclomatic complexity outweigh the cost of the allocation. see what you think.

probably won't be able to make any updates for the next week and a half due to other commitments.

Copy link
Copy Markdown
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

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

Here are my initial comments.

Did you have a chance to compare with my branch?

Comment thread Src/IronPython/Runtime/Operations/PythonOps.cs
Comment thread Src/IronPython/Compiler/Ast/SequenceExpression.cs Outdated
Comment thread Src/IronPython/Compiler/Parser.cs
Comment thread Src/IronPython/Compiler/Parser.cs
Comment thread Src/IronPython/Compiler/Parser.cs

if (left != null) {
Debug.Assert(left.Count > 0);
CheckNotAssignmentTargetOnly(right);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not that I necessarily have an issue with doing this as an initial implementation, but CPython doesn't do these checks in the parser. For example, with CPython you can do x = ast.parse("a = 1,*b") without problem, with this implementation, ast.parse will throw. I should only fail when you try to compile the AST (e.g. compile(x, None, 'exec')).

If you want to be sneaky, with CPython you can print the AST, construct the same in IronPython (you can't use ast.parse since that uses the parser), compile and end up with a TypeError: Unexpected expr type: IronPython.Modules._ast+Starred.

As I mention, I am fine with not going down that rabbit hole for now since we're in the world of invalid Python code anyway. Although, we should definitely file an issue if we go ahead and merge this in.

Comment thread Src/IronPython/Compiler/Parser.cs Outdated
Comment thread Src/IronPython/Compiler/Parser.cs Outdated
Comment thread Src/IronPython/Compiler/Parser.cs
Comment thread Src/IronPython/Compiler/Parser.cs Outdated
ret = new ListExpression();
} else {
bool prevAllow = _allowIncomplete;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a note on style: } else {

If you're using VS then formatting the document should pick up the editorconfig and apply the correct style throughout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've got VS and also ReSharper. My auto-format is currently doing too much as it is setup to match the StyleCop format, however closing an outer brace works.

I could take a look at formalizing the coding standard with some analyzers if you are interested?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there an analyzer that picks up the rules from editorconfig? Some parts of the codebase (e.g. BZip2 and c#sqlite) have their own inconsistent style (although I haven't set up an editorconfig for those).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No, but VS with ReSharper should pick it up.

CheckNotAssignmentTargetOnly(right);

var target = left.ToArray();
var target = left?.ToArray() ?? new [] { singleLeft };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking at the method without context it wasn't clear that singleLeft is never null at this point. I wonder if it's worth adding Debug.Assert(singleLeft != null). Maybe also Debug.Assert(PeekToken(TokenKind.Assign)) at the top of the method?

@slozier
Copy link
Copy Markdown
Contributor

slozier commented Nov 14, 2019

@hackf5 Any other plans for this PR? Otherwise I'm happy with it and will merge it in.

@slozier slozier merged commit 3dfe804 into IronLanguages:master Nov 24, 2019
@slozier
Copy link
Copy Markdown
Contributor

slozier commented Nov 24, 2019

Thanks for the PR!

@ghost
Copy link
Copy Markdown

ghost commented Nov 26, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError in variable unpacking

3 participants