Message393473
I noticed that __getitem__ message, although helpful, could be improved a bit further. This will also make it consistent with other error messages such as the ones raised by `str.count`, `str.split`, `str.endswith` and so many others.
Currently, the error message goes like this: "TypeError: string indices must be integers" but we could specify the type of the object passed as argument to __getitem__. So, for example:
```
>>> idx = '1'
>>> s = 'abcde'
>>> s[idx]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: string indices must be integers, not 'str'
```
This makes easier to debug and it is also consistent with other methods:
>>> "alala".count(8)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str, not int
>>> "lala|helo".split(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str or None, not int
>>> 1 in "lala"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand, not int
>>> "lala|helo".split(object())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str or None, not object |
|
Date |
User |
Action |
Args |
2021-05-11 20:50:25 | miguendes | set | recipients:
+ miguendes |
2021-05-11 20:50:25 | miguendes | set | messageid: <1620766225.38.0.0603325093774.issue44110@roundup.psfhosted.org> |
2021-05-11 20:50:25 | miguendes | link | issue44110 messages |
2021-05-11 20:50:25 | miguendes | create | |
|