Message302738
I'm not sure that this is an enhancement. It makes an error message inconsistent with other error messages.
>>> class I(int): pass
...
>>> I()[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'I' object does not support indexing
>>> 0[0] = 0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object does not support item assignment
>>> del 0[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object does not support item deletion
>>> ''['']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string indices must be integers, not str
>>> iter(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> reversed(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence
>>> next(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: int object is not an iterator
>>> {}[[]]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
And actually this message is misleading. An attribute '__getitem__' is not looked up on objects.
>>> class I(int): pass
...
>>> x = I()
>>> x.__getitem__ = lambda *args: None
>>> I()[0:]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'I' object has no attribute '__getitem__'
>>> x.__getitem__
<function <lambda> at 0x7f11b62dd648> |
|
Date |
User |
Action |
Args |
2017-09-22 06:26:33 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, Anthony Sottile |
2017-09-22 06:26:33 | serhiy.storchaka | set | messageid: <1506061593.47.0.497142353818.issue31550@psf.upfronthosting.co.za> |
2017-09-22 06:26:33 | serhiy.storchaka | link | issue31550 messages |
2017-09-22 06:26:33 | serhiy.storchaka | create | |
|