[Python-ideas] Variable-length, homogeneous tuple: why? (was: Optional static typing -- the crossroads)

Jukka Lehtosalo jlehtosalo at gmail.com
Mon Aug 18 03:01:47 CEST 2014


On Sun, Aug 17, 2014 at 5:30 PM, Guido van Rossum <guido at python.org> wrote:

> On Sun, Aug 17, 2014 at 4:47 PM, Łukasz Langa <lukasz at langa.pl> wrote:
>
>> That's a neat trick and I think Guido suggested this naming before. It
>> feels a little icky though, consider:
>>
>> - issubclass(tuple[int, int, int], frozenlist[int]) ?  I think True.
>> - issubclass(frozenlist[int], tuple[int, int, int]) ?  I would think
>> False. But because that's technically the same tuple underneath,
>> *sometimes* instances of frozenlist[int] will respond True to
>> isinstance(tuple[int, int, int]).
>>
>> Saying explicitly tuple[int, ...] takes that riddle away.
>>
>
> Hm. That looks just as [tr]icky. Plus, I expect both pedants and
> ignoramuses may wonder about the empty tuple. :-) I think it deserves a
> proper name, not magic syntax.
>
> I do agree that frozentuple sounds odd, but perhaps we just need to get
> used to it.
>

I've considered adding a mypy type for arbitrary-length tuples [1]. My
original idea was to call it TupleSequence[T], since it's basically a
concrete tuple that is used like a sequence.

Fixed-length tuples can already be used as abstract iterables and sequences:

    def f(x: Iterable[int]) -> None: pass
    f((1, 2, 3))   # Ok

[1] https://github.com/JukkaL/mypy/issues/184

Jukka


>
> --
> --Guido van Rossum (python.org/~guido)
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140817/9dcd4f6e/attachment.html>


More information about the Python-ideas mailing list