Eric Smith <[email protected]> added the comment:
get_integer uses the narrowest possible definition for integer indexes, in
order to pass all other strings to mappings.
>>> '{0[ 0 ]} {0[-1]}'.format({' 0 ': 'foo', '-1': 'bar'})
'foo bar'
Remember, it has to guess what type of lookup to do based on whether the value
inside [] looks like an integer or not.
>From the PEP:
Because keys are not quote-delimited, it is not possible to
specify arbitrary dictionary keys (e.g., the strings "10" or
":-]") from within a format string.
I don't believe this restriction causes any practical problem.
I'm not sure the error could be improved. The code that's being called is
essentially:
>>> [0, 1, 2]['-1']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not str
----------
resolution: -> rejected
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue8985>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com