This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author miguendes
Recipients miguendes
Date 2021-05-11.20:50:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620766225.38.0.0603325093774.issue44110@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-05-11 20:50:25miguendessetrecipients: + miguendes
2021-05-11 20:50:25miguendessetmessageid: <1620766225.38.0.0603325093774.issue44110@roundup.psfhosted.org>
2021-05-11 20:50:25miguendeslinkissue44110 messages
2021-05-11 20:50:25miguendescreate