https://bugs.kde.org/show_bug.cgi?id=359915

            Bug ID: 359915
           Summary: Tuple unpacking in a list comprehension not supported
           Product: kdev-python
           Version: frameworks
          Platform: Other
                OS: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: Language support
          Assignee: m...@svenbrauch.de
          Reporter: nicolas.alva...@gmail.com

When a list comprehension has multiple identifiers in the 'for' clause, it's
supposed to do sequence unpacking. This has several problems in kdev-python.

In the simplest case, variables are identified but not given the correct types:
    data = [('a',1), ('b',2)] # data is 'list of tuple of (str,int)'
    strs = [a for a,b in data] # 'a' is mixed, 'b' is mixed, 'strs' is 'list of
mixed'
It should be able to recognize that 'a' is str and 'b' is int.

If there are nested tuples, the inner ones aren't even recognized as variable
declarations (related: bug 314024):
    data2 = [(1, ('x', 3.0)), (2, ('y', 4.5))] # list of tuple of ( int, tuple
of ( str, float ) )
    [a for (a,(b,c)) in data2] # 'a' is mixed, 'b' and 'c' are underlined as
undefined variables

And here is an almost-realistic ultimate sample that would go great in the test
suite :)
    users = {'a':19, 'b':42, 'c':35}
    sorted_list = sorted(users.items(), key=lambda kv: (-kv[1], kv[0]))
    result = [(r,k,v) for r,(k,v) in enumerate(sorted_list, 1)] # 'result'
should be a tuple of (int, str, int)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to