codon
codon copied to clipboard
Suggested feature specialize typing for small lists with constant indexes
a = [1, "asdf", 2.0]
a[0] = 4
print a[0]
Unfortunately sometimes folks use small lists when they really should be using tuples, so the above code doesn't work.
However, these can be recognized and converted into tuples and given your bi-directional IR this shouldn't be too hard.
I do this in https://github.com/jplevyak/pyc by global constant propagation and specialization.
They general way we're planning to handle cases like this is by promoting the list's type to a union, e.g. Union[int, str, float]
in your case. Codon does support unions already, but doesn't yet do this automatic promotion. In certain cases we could also potentially just convert the list to a tuple as you mentioned.