[Python-ideas] Trial balloon: adding variable type declarations in support of PEP 484

אלעזר elazarg at gmail.com
Mon Aug 8 18:08:48 EDT 2016


On Tue, Aug 9, 2016 at 12:29 AM Guido van Rossum <guido at python.org> wrote:

> On Mon, Aug 8, 2016 at 2:11 PM, אלעזר <elazarg at gmail.com> wrote:
>
>> Feels like named parameters are better off being an OrderedDict in the
>> first place.
>>
>
> PEP 468.
>
>
Sorry, I should have read this PEP before.


> NamedTuple pushes OrderedDict to become kind of builtin.
>>
>
> Why? Having both in the collections module is good enough.
>

What I meant in becoming builtin is not the accessibility of the name, but
the parallel incremental support of namedtuple, OrderedDict and (as I find
out) order of **kwargs.

In much the same way that class is made out of dict (and keeps one),
namedtuple is an OrderedDict (and keeps one).
Much like dict has a constructor `dict(a=1, b=2.0)` and a literal `{'a' :
1, 'b' : 2.0}`, OrderedDict has its OrderedDict(a=1, b=2.0) and should have
the literal ('a': 1, 'b': 2.0).

Replace 1 and 2 with int and float and you get a very natural syntax for a
NamedTuple that is the type of a matching OrderedDict.
And in my mind, the requirement for type names matches nicely the
enforcement of immutability.

Continuing this thought, the annotations for the class is actually its
structural type. It opens the door for future requests for adding e.g. an
operator for structural equivalence.

This is all very far from the current language, so it's only thoughts and
not really ideas; probably does not belong here. Sorry about that.

~Elazar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160808/87d3aa2e/attachment.html>


More information about the Python-ideas mailing list