On Mon, Aug 8, 2016 at 3:08 PM, אלעזר <elaz...@gmail.com> wrote:
> On Tue, Aug 9, 2016 at 12:29 AM Guido van Rossum <gu...@python.org> wrote: > >> On Mon, Aug 8, 2016 at 2:11 PM, אלעזר <elaz...@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. > No problem, it's fine to participate before reading *everything*! > 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. > Well, they're all already in the stdlib, although namedtuple is written in Python, OrderedDict in C (recently), and **kwarg is ancient. > In much the same way that class is made out of dict (and keeps one), > namedtuple is an OrderedDict (and keeps one). > I'm not sure if you're talking about the class or the instances. A class instance usually has a dict (unless if it has __slots__ and all its base classes have __slots__). But a namedtuple instance does not have a dict or OrderedDict -- it is a tuple at heart. > 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). > That's debatable at least, and probably there are better solutions. > 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 > -- --Guido van Rossum (python.org/~guido)
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/