Rewrite visitAssignment()

Authored by flherne on Jun 2 2016, 7:18 PM.



Adds support for PEP-3132 'Extended Iterable Unpacking', fix several other bugs, and add tests for these.

Support assignments of the form a, *b, c = 1, 2, 3, 4, 5, after which b is [2, 3, 4].

Fix assignments of the form a = b = 7, a = b = 3, 4.

Fix assignment from a single-element tuple: foo = (3,) makes foo a tuple, not int.
Fix unpacking into a single-element tuple: foo, = [7] makes foo an int, not a list.

Fix unpacking of nested tuples: foo, (bar, baz) = 2, ('a', 5.5).

Declaration aliasing works for simple "a = b" assignment, e.g.

def aaa(a: int):
    return "a"
bbb = aaa

It _doesn't_ work for anything more advanced, e.g.

def aaa(a: int):
    return "a"
bbb, ccc = aaa, 4

although the function type is preserved.

This is a regression, aliasing works for non-nested tuple assignment without this patch. Sven told me not to worry about that yet...

Test Plan

Typed stuff, compared results with python interpreter output.

Wrote and added some tests.

Diff Detail

R53 KDevelop: Python Support
Lint Skipped
Unit Tests Skipped
flherne updated this revision to Diff 4175.Jun 2 2016, 7:18 PM
flherne retitled this revision from to Rewrite visitAssignment().
flherne updated this object.
flherne edited the test plan for this revision. (Show Details)
flherne added a reviewer: brauch.
flherne set the repository for this revision to R53 KDevelop: Python Support.
Restricted Application added a subscriber: kdevelop-devel. ยท View Herald TranscriptJun 2 2016, 7:18 PM
flherne updated this object.Jun 2 2016, 7:19 PM
flherne updated this object.
flherne updated this object.
flherne updated this object.
brauch accepted this revision.Jun 2 2016, 7:30 PM
brauch edited edge metadata.

Looks good to me. I wanted that fixed for ages, and nice list of tests, too :)
I think this is a good trade against losing aliasing through tuple assignment ...

This revision is now accepted and ready to land.Jun 2 2016, 7:30 PM
flherne closed this revision.Nov 20 2016, 3:59 PM

Landed months ago, but the commit-message tag was slightly wrong so this didn't get closed.