Address Serhiy's comments
This commit is contained in:
parent
6bd3a9dd6a
commit
29c17aa8ce
19
pep-0455.txt
19
pep-0455.txt
|
@ -35,11 +35,11 @@ according to their respective id()s instead of normal matching.
|
|||
|
||||
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.
|
||||
``str.lower`` or ``str.casefold`` in the former example and the built-in
|
||||
``id`` function in the latter.
|
||||
|
||||
(it can be said that the pattern *projects* keys from the user-visible
|
||||
set onto the internal lookup set, hence this PEP's title)
|
||||
(it could be said that the pattern *projects* keys from the user-visible
|
||||
set onto the internal lookup set)
|
||||
|
||||
|
||||
Semantics
|
||||
|
@ -53,7 +53,7 @@ won't rehash the semantics of most TransformDict methods.
|
|||
The transformation function needn't be bijective, it can be strictly
|
||||
surjective as in the case-insensitive example::
|
||||
|
||||
>>> d = TransformDict(str.lower)
|
||||
>>> d = TransformDict(str.casefold)
|
||||
>>> d['SomeKey'] = 5
|
||||
>>> d['somekey']
|
||||
5
|
||||
|
@ -62,7 +62,7 @@ surjective as in the case-insensitive example::
|
|||
|
||||
TransformDict retains the first key used when creating an entry::
|
||||
|
||||
>>> d = TransformDict(str.lower)
|
||||
>>> d = TransformDict(str.casefold)
|
||||
>>> d['SomeKey'] = 1
|
||||
>>> d['somekey'] = 2
|
||||
>>> list(d.items())
|
||||
|
@ -89,7 +89,7 @@ to initialize the TransformDict with certain key-value pairs. Those
|
|||
optional arguments are the same as in the ``dict`` and ``defaultdict``
|
||||
constructors::
|
||||
|
||||
>>> d = TransformDict(str.lower, [('Foo': 1)], Bar=2)
|
||||
>>> d = TransformDict(str.casefold, [('Foo', 1)], Bar=2)
|
||||
>>> sorted(d.items())
|
||||
[('Bar', 2), ('Foo', 1)]
|
||||
|
||||
|
@ -175,8 +175,9 @@ Identity dicts have been requested too:
|
|||
* https://mail.python.org/pipermail/python-ideas/2010-May/007235.html
|
||||
* http://www.gossamer-threads.com/lists/python/python/209527
|
||||
|
||||
Python's own pickle module uses identity lookups for object
|
||||
memoization: http://hg.python.org/cpython/file/0e70bf1f32a3/Lib/pickle.py#l234
|
||||
Several modules in the standard library use identity lookups for object
|
||||
memoization, for example ``pickle``, ``json``, ``copy``, ``cProfile``,
|
||||
``doctest`` and ``_threading_local``.
|
||||
|
||||
|
||||
Copyright
|
||||
|
|
Loading…
Reference in New Issue