D5442: Get correct type when slicing tuple with constant parameters.

Francis Herne noreply at phabricator.kde.org
Fri Apr 14 01:23:19 UTC 2017


flherne created this revision.
Restricted Application added a subscriber: kdevelop-devel.

REVISION SUMMARY
  Currently slicing a tuple gets the original type, which is almost always incorrect (because in that case, the user wouldn't do it...)
  
  It's quite common to take tuple slices between fixed indices, e.g.
  
    foo = 1, 2.4, "str"
    bar = foo[1:]   # tuple of (float, str)
    baz = foo[::-2]  # tuple of (str, int)
  
  This patch gets the correct type if all three parameters (start, stop, step) are either integer literals or left empty. Otherwise it returns an empty tuple. Better would be an unsure-content tuple, but that doesn't exist yet.

TEST PLAN
  Fixes one existing test, no test regressions. Needs some more cases in the test suite.
  
  Manual testing seems okay so far.

REPOSITORY
  R53 KDevelop: Python Support

REVISION DETAIL
  https://phabricator.kde.org/D5442

AFFECTED FILES
  duchain/expressionvisitor.cpp
  duchain/tests/pyduchaintest.cpp

To: flherne, brauch
Cc: kdevelop-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20170414/7ea2c04e/attachment-0001.html>


More information about the KDevelop-devel mailing list