Bug 359912 - Type not recognized in expressions with multiple subscripts
Summary: Type not recognized in expressions with multiple subscripts
Status: RESOLVED FIXED
Alias: None
Product: kdev-python
Classification: Developer tools
Component: Language support (show other bugs)
Version: frameworks
Platform: Other Linux
: NOR normal
Target Milestone: 1.7.3
Assignee: Sven Brauch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-29 02:51 UTC by Nicolás Alvarez
Modified: 2016-11-20 19:29 UTC (History)
2 users (show)

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 2016-02-29 02:51:51 UTC
If I use multiple subscripts like a[0][1], the type of the expression is shown as 'mixed', even in cases where doing the subscripts separately with a temporary variable gives the correct type.

Example code:
class Inner:
    pass

class Middle:
    def __getitem__(self, key):
        return Inner()

class Outer:
    def __getitem__(self, key):
        return Middle()

aaa = Outer() # 'aaa' is Outer
bbb = aaa[0]  # 'bbb' is Middle
ccc = bbb[0]  # 'ccc' is Inner

ggg = aaa[0][0]   # 'ggg' is mixed, should be Inner
hhh = (aaa[0])[0] # this doesn't help, still mixed

Curiously, it does work for list (and maybe for all TypeContainers?):
mylist = [[['a']]]

x1 = mylist[0][0] # list of str
x2 = mylist[0][0][0] # str
Comment 1 Francis Herne 2016-07-12 15:00:23 UTC
This is broken when subscripting most expressions that aren't simply names, in cases where the returned type is found by looking at __getitem__(). Lists, tuples, dicts and some other builtin types are handled separately.

Another example:
class SomeClass:
    def __getitem__(self, key):
        return "Test"

def some_func():
    return SomeClass()

aaa = some_func()[3] # should be str, but is mixed.

I'll try to fix it, if I can find how all this Declaration stuff works.
Comment 2 Francis Herne 2016-11-20 15:56:19 UTC
Git commit 3a534dbb961fa3757e7066583b5a24c16525ea5f by Francis Herne.
Committed on 20/11/2016 at 15:48.
Pushed by flherne into branch 'master'.

Pass AbstractType::Ptr, not Declaration*, to accessAttribute()

All but one caller had to look up the declaration only to have it converted
  back, so the previous version was pointless anyway.

This allows subscripting of expressions (inc. other subscripts), when the
  subscripted type isn't a ListType/IndexedContainer.
Differential Revision: https://phabricator.kde.org/D3422

M  +1    -1    duchain/declarationbuilder.cpp
M  +3    -6    duchain/expressionvisitor.cpp
M  +3    -3    duchain/helpers.cpp
M  +1    -1    duchain/helpers.h
M  +9    -0    duchain/tests/pyduchaintest.cpp

http://commits.kde.org/kdev-python/3a534dbb961fa3757e7066583b5a24c16525ea5f