Get correct type when slicing tuple with constant parameters.
ClosedPublic

Authored by flherne on Apr 14 2017, 1:23 AM.

Details

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.

Diff Detail

Repository
R53 KDevelop: Python Support
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
flherne created this revision.Apr 14 2017, 1:23 AM
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptApr 14 2017, 1:23 AM
brauch accepted this revision.Apr 14 2017, 8:05 AM

Looks fine to me! Thanks a lot once again :)

This revision is now accepted and ready to land.Apr 14 2017, 8:05 AM
This revision was automatically updated to reflect the committed changes.