[Python-Dev] Non-string keys in type dict (original) (raw)

Brett Wilkins brett at brett.geek.nz
Thu Mar 8 02:48:59 CET 2012


I assume when you say "non-string keys" this includes numbers.

But in Pypy, I can certainly use numbers:

{'1':1, 1:2}.keys() ['1', 1]

I can even use a lambda (obviously not a string, a number, nor what I would consider a primitive):

{'1':1, (lambda x: x):2}.keys() ['1', <function at 0x00007fdb0b837da8>]

These are in Pypy 1.8.

--Brett

On Thu 08 Mar 2012 14:39:40 NZDT, Victor Stinner wrote:

Hi,

During the Language Summit 2011 (*), it was discussed that PyPy and Jython don't support non-string key in type dict. An issue was open to emit a warning on such dict, but the patch has not been commited yet. I'm trying to Lib/test/crashers/losingmroref.py: I wrote a patch fixing the specific issue (keep a strong reference to the MRO during the lookup, see #14199), but I realized that the real problem is that we allow custom objects in the type dict. So my question is: what is the use case of such dict? Why do we still support it? Can't we simply raise an error if the dict contains non-string keys? (*) http://blog.python.org/2011/03/2011-language-summit-report.html Victor


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/brett%40brett.geek.nz



More information about the Python-Dev mailing list