[issue18986] Add a case-insensitive case-preserving dict

2015-05-16 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
status: open - pending

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-05-16 Thread Ethan Furman

Ethan Furman added the comment:

From https://mail.python.org/pipermail/python-dev/2015-May/140003.html
==
Before the Python 3.5 feature freeze, I should step-up and
formally reject PEP 455 for Adding a key-transforming
dictionary to collections.

I had completed an involved review effort a long time ago
and I apologize for the delay in making the pronouncement.

What made it a interesting choice from the outset is that the
idea of a transformation is an enticing concept that seems
full of possibility.  I spent a good deal of time exploring
what could be done with it but found that it mostly fell short
of its promise.

There were many issues.  Here are some that were at the top:

* Most use cases don't need or want the reverse lookup feature
  (what is wanted is a set of one-way canonicalization functions).
  Those that do would want to have a choice of what is saved
  (first stored, last stored, n most recent, a set of all inputs,
  a list of all inputs, nothing, etc).  In database terms, it
  models a many-to-one table (the canonicalization or
  transformation function) with the one being a primary key into
  another possibly surjective table of two columns (the
  key/value store).  A surjection into another surjection isn't
  inherently reversible in a useful way, nor does it seem to be a
  common way to model data.

* People are creative at coming up with using cases for the TD
  but then find that the resulting code is less clear, slower,
  less intuitive, more memory intensive, and harder to debug than
  just using a plain dict with a function call before the lookup:
  d[func(key)].  It was challenging to find any existing code
  that would be made better by the availability of the TD.

* The TD seems to be all about combining data scrubbing
  (case-folding, unicode canonicalization, type-folding, object
  identity, unit-conversion, or finding a canonical member of an
  equivalence class) with a mapping (looking-up a value for a
  given key).  Those two operations are conceptually orthogonal.
  The former doesn't get easier when hidden behind a mapping API
  and the latter loses the flexibility of choosing your preferred
  mapping (an ordereddict, a persistentdict, a chainmap, etc) and
  the flexibility of establishing your own rules for whether and
  how to do a reverse lookup.


Raymond Hettinger


P.S.  Besides the core conceptual issues listed above, there
are a number of smaller issues with the TD that surfaced
during design review sessions.  In no particular order, here
are a few of the observations:

* It seems to require above average skill to figure-out what
  can be used as a transform function.  It is more
  expert-friendly than beginner friendly.  It takes a little
  while to get used to it.  It wasn't self-evident that
  transformations happen both when a key is stored and again
  when it is looked-up (contrast this with key-functions for
  sorting which are called at most once per key).

* The name, TransformDict, suggests that it might transform the
  value instead of the key or that it might transform the
  dictionary into something else.  The name TransformDict is so
  general that it would be hard to discover when faced with a
  specific problem.  The name also limits perception of what
  could be done with it (i.e. a function that logs accesses
  but doesn't actually change the key).

* The tool doesn't self describe itself well.  Looking at the
  help(), or the __repr__(), or the tooltips did not provide
  much insight or clarity.  The dir() shows many of the
  _abc implementation details rather than the API itself.

* The original key is stored and if you change it, the change
  isn't stored.  The _original dict is private (perhaps to
  reduce the risk of putting the TD in an inconsistent state)
  but this limits access to the stored data.

* The TD is unsuitable for bijections because the API is
  inherently biased with a rich group of operators and methods
  for forward lookup but has only one method for reverse lookup.

* The reverse feature is hard to find (getitem vs __getitem__)
  and its output pair is surprising and a bit awkward to use.
  It provides only one accessor method rather that the full
  dict API that would be given by a second dictionary.  The
  API hides the fact that there are two underlying dictionaries.

* It was surprising that when d[k] failed, it failed with
  transformation exception rather than a KeyError, violating
  the expectations of the calling code (for example, if the
  transformation function is int(), the call d[12]
  transforms to d[12] and either succeeds in returning a value
  or in raising a KeyError, but the call d[12.0] fails with
  a TypeError).  The latter issue limits its substitutability
  into existing code that expects real mappings and for
  exposing to end-users as if it were a normal dictionary.

* There were other issues with dict invariants as well and
  

[issue18986] Add a case-insensitive case-preserving dict

2015-02-28 Thread Jason R. Coombs

Jason R. Coombs added the comment:

I'm also eager to hear what limitations prevented the acceptance. Please do 
link back here when you've posted.

I have to say, I'm not entirely surprised. In my implementation, I struggled 
with some cases, and it certainly doesn't feel like a fully safe implementation.

That said, since I mentioned the implementation in jaraco.util earlier, I 
wanted to announce that those implementations (FoldedCase and 
FoldedCaseKeyedDict) have been moved to two libraries (jaraco.text and 
jaraco.collections).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-02-18 Thread Demian Brecht

Demian Brecht added the comment:

 I will be interested to see those reasons.

+1. Something like what this PEP proposed would be beneficial in a few places 
throughout the library (header and cookie implementations would definitely 
benefit rather than having to deal with buggy normalization themselves). It’s 
unfortunate that this isn’t going to be approved.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-02-17 Thread Martin Panter

Martin Panter added the comment:

I will be interested to see those reasons. Another way to do a similar thing 
might be using a Key(value, transform) class, somewhat along the lines of Issue 
20632, but as a separate class rather than part of the core type system. But I 
have not thought that idea through very much.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-02-17 Thread Raymond Hettinger

Raymond Hettinger added the comment:

FYI, the PEP for this isn't going to be accepted (I'm working on the write-up 
for the reasons why and will post on python-dev).   That said, it would be 
great if the code continues to be improved and then posted on the Python 
Package Index.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-02-16 Thread Demian Brecht

Demian Brecht added the comment:

Some refactoring that I'm working on for http.client could use this (currently 
I have it as part of my patch set). I haven't run into any issues using it and 
it's definitely useful. Would be nice to get this merged.

--
nosy: +demian.brecht

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-01-15 Thread STINNER Victor

STINNER Victor added the comment:

The API is simple and well defined, the addition is small, I don't understand 
what is the problem with this enhancement.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-01-15 Thread Martin Panter

Martin Panter added the comment:

For the record, this is related to PEP 455 (key-transforming dictionary)

--
nosy: +vadmium

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-01-14 Thread Ethan Furman

Ethan Furman added the comment:

3.5 is almost here; Raymond, care to make a ruling?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2015-01-14 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Yes.

I intend to button this one up before long.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-12-14 Thread Raymond Hettinger

Raymond Hettinger added the comment:

[Mark Dickinson]
 It's essentially an IdentityDict, though I've found other 
 more specific transforms useful.

Have any of the applications had use for the part of the API that looks up the 
original, untransformed key?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-12-14 Thread Mark Dickinson

Mark Dickinson added the comment:

Not my applications, no.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-12-13 Thread Mark Dickinson

Mark Dickinson added the comment:

 Mark, what was the use case you found?

It's essentially an IdentityDict, though I've found other more specific 
transforms useful.

I was writing a tool to find reference cycles between Python objects (we have a 
customer application that's working in a multithreaded COM environment and has 
to ensure that COM objects are released on the same types of threads they were 
created on, so we have to be careful about cyclic garbage and delayed garbage 
collection).

The graph of Python objects (class 'ObjectGraph') is modelled as a fairly 
standard directed graph (set of vertices, set of edges, two dictionaries 
mapping each edge to its head and tail), but of course for this application the 
dict and set have to be based on object identity rather than normal equality.  
Using a TransformDict (and an IdentitySet) lets me write the standard graph 
algorithms (e.g., for finding strongly connected components) in a natural way, 
leaving it to the TransformDict and IdentitySet to do the necessary id() 
conversions under the hood.)

I also have a similar AnnotatedGraph object (a sort of offline version of the 
ObjectGraph), where the edges and vertices carry additional information and 
it's convenient to be able to use a lightweight ID rather than an entire vertex 
or edge as a dictionary key.  Again, using a TransformDict lets one hide the 
details and present the graph manipulation code readably and naturally.

Some code here, if you're interested:

https://github.com/mdickinson/refcycle/blob/refactor/refcycle/object_graph.py

Caveat: it's work in progress.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-12-13 Thread Eli Bendersky

Changes by Eli Bendersky eli...@gmail.com:


--
nosy:  -eli.bendersky

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-12-12 Thread Mark Dickinson

Mark Dickinson added the comment:

+1 for this (for Python 3.5, now, I guess). I've just found another place where 
I'd use it.

Looking at the implementation, one thing surprises me a bit:  I'd expect the 
KeyError from a 'del' or 'pop' operation to have the untransformed key rather 
than the transformed key in its .args.

How about '_keys' and '_values' for the slot names, in place of '_original' and 
'_data'?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-12-12 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Mark, what was the use case you found?

--
versions: +Python 3.5 -Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-10-13 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Antoine, is the PEP ready for review?

Well, I think it is. Do you think other points should be addressed in it?
We still have some time.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-10-13 Thread Mark Dickinson

Changes by Mark Dickinson dicki...@gmail.com:


--
nosy: +mark.dickinson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-10-12 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Antoine, is the PEP ready for review?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-10-04 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
assignee:  - rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-10-03 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Raymond, have you had time to look at this?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-22 Thread Jason R. Coombs

Jason R. Coombs added the comment:

I just want to say thanks for working on this. I also have needed this 
functionality for various needs in the past. To fulfill my needs, I wrote this 
implementation:

https://bitbucket.org/jaraco/jaraco.util/src/1ab3e7061f96bc5e179b6b2c46b06d1c20f87129/jaraco/util/dictlib.py?at=default#cl-221

That implementation is used in the irc library for a case-insensitive dict, but 
using the IRC-specific standard for case insensitivity 
(https://bitbucket.org/jaraco/irc/src/1576b10dc2923d4d7234319d2d1e11a5080e1f7d/irc/dict.py?at=default#cl-49).

I share this just to add a +1 for the need and to provide additional use cases 
and implementations for reference.

--
nosy: +jason.coombs

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Georg Brandl

Georg Brandl added the comment:

Note that I'm strongly against this name of the getitem() method.

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Georg Brandl added the comment:
 
 Note that I'm strongly against this name of the getitem() method.

Any suggestion?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Georg Brandl

Georg Brandl added the comment:

Not really. Would entry be acceptable instead of item?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Georg Brandl added the comment:
 
 Not really. Would entry be acceptable instead of item?

getentry() sounds decent to me, but it loses the parallel to popitem() and 
items().

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Georg Brandl

Georg Brandl added the comment:

Hmm, I didn't consider popitem().  Maybe I'm too paranoid about users confusing 
__getitem__() and getitem() after all :)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

But why not getkey()? Why you need return value too?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 But why not getkey()? Why you need return value too?

Because it's more useful to return both.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Sorry, I don't understand why it's more useful. We need create a tuple and then 
index it or unpack it and drop one of elements. This only muddles away a time 
and programmer's attention.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread R. David Murray

R. David Murray added the comment:

Because most often the time at which you want the original key is the point at 
which you are about to re-serialize the data...so you need the value too.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread R. David Murray

R. David Murray added the comment:

I do think getitem is the most natural name for the method.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Eric V. Smith

Eric V. Smith added the comment:

On 09/17/2013 09:34 AM, R. David Murray wrote:
 
 R. David Murray added the comment:
 
 Because most often the time at which you want the original key is the point 
 at which you are about to re-serialize the data...so you need the value too.

I can't think of a case where I'd need (original_key, value) where I
wouldn't also be iterating over items(). Especially so if I'm serializing.

On the other hand, I don't have a use case for the original key, anyway.
So I don't have a strong feeling about this, other than it feels odd
that the answer to the original question (I think on python-dev) how do
we get the original key back? is answered by by giving you the
original key and its value.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Oh, could anyone borrow Guido's time machine and rename either __getitem__() to 
__getvalue__() or items() to entries()?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-17 Thread Eric V. Smith

Eric V. Smith added the comment:

On 09/17/2013 10:12 AM, Eric V. Smith wrote:
 On the other hand, I don't have a use case for the original key, anyway.
 So I don't have a strong feeling about this, other than it feels odd
 that the answer to the original question (I think on python-dev) how do
 we get the original key back? is answered by by giving you the
 original key and its value.

I meant: I don't have a use case for finding the original key outside of
iterating over items().

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Note: I haven't renamed transformdict to TransformDict yet.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Updated patch adding the getitem() method.

--
Added file: http://bugs.python.org/file31757/transformdict2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-14 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Uploading new patch with added transform_func property.

--
Added file: http://bugs.python.org/file31761/transformdict3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is an alternative C implementation. It adds to the dict class support of 
the __transform__() method. If this method is defined in dict subclass it used 
to transforming keys. collections.TransformDict is just utilizes this feature 
as collections.defaultdict utilizes __missing__(). This patch changes twice 
less C code than previous one (227 vs 474 lines).

--
Added file: http://bugs.python.org/file31749/dict__transform__.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 Does it slow down regular dicts?

I were surprized, but yes. The ComplexPythonFunctionCalls test from pybench is 
40% slower with ctransformdict.patch (and I still don't known why). With 
dict__transform__.patch it is only 2% slower. All other pybench tests are 
approximately equal.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-13 Thread Antoine Pitrou

Antoine Pitrou added the comment:

  Does it slow down regular dicts?
 
 I were surprized, but yes. The ComplexPythonFunctionCalls test from
 pybench is 40% slower with ctransformdict.patch (and I still don't
 known why). With dict__transform__.patch it is only 2% slower. All
 other pybench tests are approximately equal.

Did you try any other microbenchmarks? Your approach sounds promising.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-13 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 Did you try any other microbenchmarks? Your approach sounds promising.

Any microbenchmarks which I tried did not show any interesting. Until I found 
the cause of slowing down ComplexPythonFunctionCalls I have no idea which tests 
can be representable.

Of course you can run benchmarks yourself.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Serhiy, any benchmarks for your implementation? Does it slow down regular dicts?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread Ethan Furman

Ethan Furman added the comment:

On 09/11/2013 02:39 PM, Tim Delaney wrote on PyDev:
 
 I would think that retrieving the keys from the dict would return the 
 transformed keys (I'd 
 call them canonical keys).

The more I think about this the more I agree.  A canonicaldict with a key 
function that simply stored the transformed key and it's value would seem to be 
a lot simpler:

  - no need to store a separate presentation key
  - no confusion about which of the first key/last key seen is stored
  - no mistakes with the first key not being added before real data
and getting the presentation key wrong

Further, in order to store the non-canonical keys a separate list must be kept 
of the keys to preseed the canonicaldict; if we store the canonical keys a 
separate list must be kept for presentation purposes -- so worst case scenario 
we're keeping the same amount of information and best-case scenario the 
presentation of the keys doesn't matter and we just saved ourselves an extra 
data structure.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread Ethan Furman

Ethan Furman added the comment:

True, but how big a deal is that?

For one, it seems questionable to have the presentation portion of the data be 
part of the key.

For two, when presentation is important a separate list must be kept anyway to 
preseed the dict; so just use that list to cycle through the canonicaldict:

-- some_dict = some_function_that_returns_a_conanicaldict()
-- presentation_list = ['IBM','Intel','AMD']
-- for company in presentation_list:
... key = some_dict.key[company]  # demo purposes only
... value = some_dict[company]
... print(key, company, value)
ibm IBM 2172
intel Intel 3210
amd AMD 4399

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread R. David Murray

R. David Murray added the comment:

It would be simpler, but it would also be useless for the actual use case for 
which this issue was opened.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 R. David Murray added the comment:
 
 You are conceptualizing this very differently.  In our view, this
 data structure is for cases where the original key is the most
 important piece of information (about the keys).  The transformation
 in the lookup process is entirely in the service of looking up the
 value paired with that original key when there is more than one
 possible representation of that key.  It is the original key that is
 critical when re-serializing the data or otherwise making use of the
 keys for anything other than lookup.  So this is about making the
 data structure succinctly model the problem domain, which is what OO
 is supposed to be good at :)

Thanks for putting it much more convincingly than my python-dev
response :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ethan, please don't post the same message *both* on the tracker
and on the mailing-list. I'm sure most people here also read
the ML thread.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread R. David Murray

R. David Murray added the comment:

You are conceptualizing this very differently.  In our view, this data 
structure is for cases where the original key is the most important piece of 
information (about the keys).  The transformation in the lookup process is 
entirely in the service of looking up the value paired with that original key 
when there is more than one possible representation of that key.  It is the 
original key that is critical when re-serializing the data or otherwise making 
use of the keys for anything other than lookup.  So this is about making the 
data structure succinctly model the problem domain, which is what OO is 
supposed to be good at :)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-12 Thread Ethan Furman

Ethan Furman added the comment:

Right, sorry.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-11 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a preliminary C implementation.

--
Added file: http://bugs.python.org/file31728/ctransformdict.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-11 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Removed file: http://bugs.python.org/file31728/ctransformdict.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-11 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Added file: http://bugs.python.org/file31729/ctransformdict.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Antoine Pitrou

Antoine Pitrou added the comment:

(now relayed on python-dev)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I'm uploading a pure Python transformdict implementation + tests, for Serhiy's 
benefits (and others') :-)

--
keywords: +patch
Added file: http://bugs.python.org/file31713/transform.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Richard Oudkerk

Richard Oudkerk added the comment:

With the current patch __repr__() will fail if the untransformed key is 
unhashable:

 d = collections.transformdict(id)
 L = [1,2,3]
 d[L] = None 
 d.keys()
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Repos\cpython-dirty\lib\collections\abc.py, line 444, in __repr__
return '{0.__class__.__name__}({0._mapping!r})'.format(self)
  File C:\Repos\cpython-dirty\lib\collections\__init__.py, line 944, in 
__repr__
self._transform, repr(dict(self)))
TypeError: unhashable type: 'list'

--
nosy: +sbt

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 With the current patch __repr__() will fail if the untransformed key
 is unhashable:

Yeah, the __repr__() implementation will be a bit annoying to get right :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Éric Araujo

Éric Araujo added the comment:

FTR this is one message from the previous thread about this: 
https://mail.python.org/pipermail/python-ideas/2010-June/007332.html

--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Updated patch: fixes repr(), and retains the first key not the last.

--
Added file: http://bugs.python.org/file31727/transformdict.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:


--
nosy: +Arfrever

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-10 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I would *really* like for this to start outside the standard library.
It needs to mature with user feedback before being dumped
in the collections module (which was never intended to be a
giant pile of every collection a person could think of).  

Adding yet more dictionary variants is an example of
way-too-many-ways-to-do-it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

New submission from Antoine Pitrou:

This is a very common need when implementing network protocols. You want to 
match keys case-insensitively but also preserve the original casing (e.g. for 
presentation).

When searching on the Web, you see many people reimplementing their own variant 
(often incomplete, or buggy). For example, Twisted has its own, the email 
package has something resembling it, WebOb also.

Having an implementation in the stdlib would spare many people the effort, 
ensure the implementation is complete and well-tested, and perhaps also add 
some optimizations to mitigate the overhead compared to a plain dict.

Note this is an instance of a more general pattern, where they key used for 
matching is derived from the lookup key using a constant derivation function. 
So maybe we want to implement the more general pattern and let users specify 
str.lower as the key derivation function.

--
components: Library (Lib)
messages: 197359
nosy: barry, pitrou, r.david.murray, rhettinger, tim.peters
priority: normal
severity: normal
status: open
title: Add a case-insensitive case-preserving dict
type: enhancement
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Thomas Heller

Changes by Thomas Heller thel...@ctypes.org:


--
nosy: +theller

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Matthew Barnett

Matthew Barnett added the comment:

Surely a case-insensitive dict should use str.casefold, not str.lower?

--
nosy: +mrabarnett

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Surely a case-insensitive dict should use str.casefold, not
 str.lower?

Perhaps. Network protocols will usually only allow ASCII in parts
where case is insensitive (e.g. header names), so it shouldn't make a
difference.

Implementing the generic pattern means this is left at the user's
discretion, though.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

For the record, I have my own implementation here:
https://bitbucket.org/optiflowsrd/obelus/src/tip/obelus/casedict.py?at=default
https://bitbucket.org/optiflowsrd/obelus/src/tip/obelus/test/test_casedict.py?at=default

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
nosy: +ethan.furman

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread R. David Murray

R. David Murray added the comment:

For the record, email is not a good argument for this, since email could not 
use this data structure (its data structure is *not* a dict, but a list with 
dict-like features grafted on).

I do think this would be useful, and the generic version (analogous to 
defaultdict) would seem to make sense.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ok, let's bikeshed this a bit. What should be the name?
- projectdict?
- normalizedict?
- normdict?
- derivedict?
- transformdict?
- any ideas?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Ethan Furman

Ethan Furman added the comment:

I would say

- transformkeydict


Too bad we can't just add an extra 'transform_key' keyword to defaultdict.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Eric V. Smith

Eric V. Smith added the comment:

It would be nice to combine the behaviors that defaultdict and the 
case-insensitive comparisons.

--
nosy: +eric.smith

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Eric V. Smith

Eric V. Smith added the comment:

Just today I was using a defaultdict where the keys are stock symbols. They're 
case insensitive (at least for this particular application).

In this case I just str.upper everything, but it would be a nice feature to 
case-preserve the keys that I pre-populate. I care less about the keys from 
user data.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 In this case I just str.upper everything, but it would be a nice
 feature to case-preserve the keys that I pre-populate. I care less
 about the keys from user data.

Well, stock symbols are what I would call user data :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Eric V. Smith

Eric V. Smith added the comment:

True enough!

I was trying to distinguish keys that I populate with initial values (mostly 
stock indexes) versus those where I just read values from a user-supplied file. 
When I populate the index values, I'd like to preserve the case I initially 
used. When I use user-supplied values, I don't know that the first value I use 
to populate the defaultdict has any more meaning that the last one I see.

It would just be a nice-to-have feature for which I have a real use case. It's 
not so critical that I can't work around it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 It would be nice to combine the behaviors that defaultdict and the 
 case-insensitive comparisons.

Any use case? In my experience they are used in completely different
situations. defaultdict mostly to use the writing of some (internal)
algorithms, a case-insensitive dict to store user-visible data.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Ethan Furman

Ethan Furman added the comment:

To the point, however, Eric's example would make use of both the defaultdict 
portion and the transformkey portion in a single dict.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Matthew Barnett

Matthew Barnett added the comment:

mappeddict?

Re defaultdict, you could write a dict that does all of these things, called 
superdict! :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread R. David Murray

R. David Murray added the comment:

coercekeydict

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I would like to shorten the proposals to transformdict and coercedict.
(after all, transforming the values would have little sense: you can do it 
yourself trivially)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread STINNER Victor

STINNER Victor added the comment:

FYI os.environ uses something similar: keys and values are encoded and decoded 
using functions. So any transformation is supported.

http://hg.python.org/cpython/file/eac63e7ceb03/Lib/os.py#l636

On UNIX, the encoder and decoder are os.fsencode() and os.fsdecode() (not 
exactly, the real functions are more strict on the input type).

On Windows, the encoder converts the key to uppercase.

--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Eli Bendersky

Eli Bendersky added the comment:

+1 For the general idea
+1 For the more generic approach of which lowercase is just one special case

+10 to make this a PEP so that more people have a chance to express their 
opinion (currently only those who noticed it on the issues mailing list). I 
find the issue tracker a very bad medium for any kind of brain-storming or 
bikeshedding.

--
nosy: +eli.bendersky

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 FYI os.environ uses something similar: keys and values are encoded and
 decoded using functions. So any transformation is supported.

I don't think this is the same situation. os.environ has bijective
transformations, which don't pose any implementation challenge.

The whole point of a transformdict is to allow for multiple keys to
actually map to the same dict entry.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 +10 to make this a PEP so that more people have a chance to express
 their opinion (currently only those who noticed it on the issues
 mailing list). I find the issue tracker a very bad medium for any kind
 of brain-storming or bikeshedding.

Well, I don't think there is a lot of brainstorming to be done here: we
are talking about a single well-defined functionality. I don't mind
writing a PEP if other people ask for it, but I'd rather spend my time
on more important things.

As for bikeshedding, there is no good medium for it, really :-) At
worse we could ask python-dev for their naming contributions (a great
idea, surely).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

See also discussion on a topic: 
http://comments.gmane.org/gmane.comp.python.ideas/18469 .

Proposed names: custom_dict, KeyedDictionary, Dictionary.

It will be confused if this dict will not be compatible with PyDict API. It is 
possible to add such feature directly into the dict class (I experimented with 
IdentityDict).

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread R. David Murray

R. David Murray added the comment:

Indeed.  Although there was apparently some call for it, it doesn't sound from 
a quick google like defaultdict was deemed to require a PEP.  Presumably the 
informed audience should be wider than this issue, though.

I also note that defaultdict is implemented via a special method on dict itself 
(__missing__), and if this one was implemented the same way it would be easy to 
combine the features.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Ethan Furman

Ethan Furman added the comment:

Precisely what I was thinking.  :)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 I also note that defaultdict is implemented via a special method on
 dict itself (__missing__), and if this one was implemented the same
 way it would be easy to combine the features.

It's not that simple: to remember the original casing you need either a
second container, or to use (original_key, value) tuples as values. Both
approaches have non-trivial repercussions on the implementation of many
methods.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

(as a sidenote, you might want a case-insensitive OrderedDict as well, I see no 
reason to make a special case for defaultdict here)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Proposed names: custom_dict, KeyedDictionary, Dictionary.

Sounds much too vague and un-specific.

 It will be confused if this dict will not be compatible with PyDict
 API.

Why? Many custom dict-like classes aren't.

 It is possible to add such feature directly into the dict class (I
 experimented with IdentityDict).

Can you explain how?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 Why? Many custom dict-like classes aren't.

And this is weird (issue10977).

 Can you explain how?

By patching Objects/dictobject.c of course. I suppose it should require 
changing about 400 lines of code, a little more than for IdentityDict. When you 
provides the specification perhaps I will provide a patch.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 By patching Objects/dictobject.c of course.

Am I stupid :-)

 I suppose it should require changing about 400 lines of code, a little
 more than for IdentityDict. When you provides the specification
 perhaps I will provide a patch.

Well, take a look at the code I've pointed to above. I'm curious to know
how you'll integrate it in dictobject.c without slowing down normal dict
objects, and without making them bigger.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 I'm curious to know how you'll integrate it in dictobject.c without slowing 
 down normal dict objects, and without making them bigger.

It of course will make a size of source file bigger, but shouldn't affect a 
size or performance of normal dicts. A dict object contains dk_lookup. 
Constructor for keyed dict (subclass of ) should initialize it with specialized 
function which calls the key function and recalculate a hash (yes, with this 
simple approach a hash will be calculated twice, for original and for 
transformed keys). Hmm, actually it can be even simpler than for IdentityDict 
(for which not calculating a hash was important). Also some other methods which 
relies on dict implementation details (e.g. making a copy of dict) should be 
modified.

The most cumbersome part is the tests. Unfortunately I lost my tests for 
IdentityDict (used hg diff without --git). It will be good if your provide 
complete test suite.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 It of course will make a size of source file bigger, but shouldn't
 affect a size or performance of normal dicts. A dict object contains
 dk_lookup.

You need to keep both the original keys and the transformed keys. It's not only 
about transforming keys on lookup. Otherwise, yes, it's trivial.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18986] Add a case-insensitive case-preserving dict

2013-09-09 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 It will be good if your provide complete test suite.

... Again, take a look at the code I've posted above ...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18986
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com