Bug 305834

Summary: Tuples not unpacked correctly in a for statement
Product: [Developer tools] kdev-python Reporter: Nicolás Alvarez <nalvarez>
Component: Language supportAssignee: Sven Brauch <mail>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: git master   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:

Description Nicolás Alvarez 2012-08-26 18:59:25 UTC
When an iterable of tuples is used in a 'for' statement, and there are multiple variables in the 'target list' (thus unpacking the tuple), their types are incorrect.

Unpacking a tuple in a normal assignment gives the correct types to the target variables:

    t = ("x", 0.5)
    a,b = t
    # 't' is tuple, 'a' is string, 'b' is float.

But when iterating over a list of tuples, and unpacking directly in the 'for' statement, KDevelop seems not to handle the unpacking at all:

    seq = [("x", 0.5)]
    for a,b in seq:
        print a

The type of 'a' shows as 'mixed' (unknown), and 'b' is typed as tuple<string,float>. Instead, 'a' should be 'string' and 'b' should be 'float'.
Comment 1 Sven Brauch 2012-08-26 19:47:31 UTC
Git commit f24284763f9b82366d8f86ee1f0f179333747d62 by Sven Brauch.
Committed on 26/08/2012 at 21:46.
Pushed by brauch into branch 'master'.

Support iterating over lists of tuples while unpacking those.

Code example:
c = [(1, 2)]
for a, b in c: print a, b # a, b are ints

should fix

M  +48   -7    duchain/declarationbuilder.cpp
M  +24   -0    duchain/expressionvisitor.cpp
M  +4    -0    duchain/tests/pyduchaintest.cpp

http://commits.kde.org/kdev-python/f24284763f9b82366d8f86ee1f0f179333747d62