Bug 305834 - Tuples not unpacked correctly in a for statement
Summary: Tuples not unpacked correctly in a for statement
Status: RESOLVED FIXED
Alias: None
Product: kdev-python
Classification: Developer tools
Component: Language support (show other bugs)
Version: git master
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Sven Brauch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-26 18:59 UTC by Nicolás Alvarez
Modified: 2012-08-26 19:47 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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