Re: [Python-Dev] PEP 455: TransformDict

2013年9月13日 12:40:14 -0700

On 2013年9月13日 22:31:02 +0300
Serhiy Storchaka <[email protected]> wrote:
> 13.09.13 21:40, Antoine Pitrou написав(ла):
> > Both are instances of a more general pattern, where a given
> > transformation function is applied to keys when looking them up: that
> > function being ``str.lower`` in the former example and the built-in
> > ``id`` function in the latter.
> 
> Please use str.casefold in examples.
> 
> > >>> d = TransformDict(str.lower, [('Foo': 1)], Bar=2)
> 
> {'Foo': 1} or [('Foo', 1)].
Ok, thanks.
> > Providing a specialized container, not generic
> > ----------------------------------------------
> >
> > It was asked why we would provide the generic TransformDict construct
> > rather than a specialized case-insensitive dict variant. The answer
> > is that it's nearly as cheap (code-wise and performance-wise) to provide
> > the generic construct, and it can fill more use cases.
> 
> Except lightweight IdentityDict which can be implemented more efficient 
> than TransformDict(id). It doesn't need in calling the transform 
> function, computing the hash of transformed key, comparing keys.
> But 
> perhaps in many cases TransformDict(id) is enough.
That's true. But it's only important if TransformDict is the
bottleneck. I doubt the memoizing dictionary is a bottleneck in
e.g. the pure Python implementation of pickle or json.
> > Python's own pickle module uses identity lookups for object
> > memoization:
> > http://hg.python.org/cpython/file/0e70bf1f32a3/Lib/pickle.py#l234
> 
> Also copy, json, cProfile, doctest and _threading_local.
Thanks, will add them.
Regards
Antoine.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to