On 8 Oct 2013 22:31, "Antoine Pitrou" <solipsis@pitrou.net> wrote:
>
> Le Tue, 8 Oct 2013 22:12:02 +1000,
> Nick Coghlan <ncoghlan@gmail.com> a écrit :
> >
> > It's OK if the key transforming API has to constrain the behaviour of
> > the underlying mapping or require an appropriately designed transform
> > function to handle more esoteric containers. Either would still be
> > better than categorically *disallowing* composition to the point
> > where you can't even compose it with OrderedDict.
>
> Well, you could ask the same question about OrderedDict, defaultdict or
> Weak*Dictionary since neither of them use composition :-)

We *did* ask the same question about those (except the Weak* variants, simply due to age).

Each time, the point that each new dict variant would be used to justify yet *more* variants was a cause for concern.

defaultdict made it through because it's just a convenience API for the underlying "key missing" protocol, while OrderedDict spent time maturing outside the standard library first.

>
> > ChainMap doesn't
> > compose sensibly with arbitrary mappings like defaultdict, but
> > composition is still the right design choice because it works well
> > with *most* custom mappings.
>
> ChainMap is easy to compose since it doesn't have to keep any
> data-driven internal state.

Yet composing ChainMap with defaultdict still breaks, because it's a conceptually incoherent thing to do.

"Composition doesn't work with some mappings" isn't an adequate answer to the criticism that a composition based design could work with more mappings than just the builtin dict.

> > It's not that I think this is necessarily a *bad* idea (although the
> > composability problem gives me grave doubts), it's that I think it's
> > not an *urgent* idea, so why rush to review and include it in the
> > weeks remaining before the beta, when the option of publishing it as
> > a recipe or a PyPI module remains available?
>
> It's just that I disagree we're rushing anything. The feature is fairly
> simple, many people have already had a need for something like that.
> (and amongst those people absolutely *zero* have said the design of the
> feature proposal is inadequate)

Except the one who wanted to combine it with OrderedDict. Users won't be able to combine it with ChainMap either.

The concrete container vs container-wrapper design decision is a fundamental one and I don't believe the current PEP adequately makes the case in favour of the former.

Cheers,
Nick.

>
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com