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
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.
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