[issue44110] Improve string's __getitem__ error message

2021-06-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Thank you for your contribution Miguel.

I decided to not backport this change to 3.10 because the benefit is too small 
in comparison with possibility to break someone's tests.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44110] Improve string's __getitem__ error message

2021-06-27 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions:  -Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44110] Improve string's __getitem__ error message

2021-06-27 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset ed1076428cca3c8dc7d075c16a575aa390e25fb8 by Miguel Brito in 
branch 'main':
bpo-44110: Improve string's __getitem__ error message (GH-26042)
https://github.com/python/cpython/commit/ed1076428cca3c8dc7d075c16a575aa390e25fb8


--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44110] Improve string's __getitem__ error message

2021-05-11 Thread Miguel Brito


Change by Miguel Brito :


--
keywords: +patch
pull_requests: +24687
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26042

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44110] Improve string's __getitem__ error message

2021-05-11 Thread Miguel Brito


New submission from Miguel Brito :

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 "", line 1, in 
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 "", line 1, in 
TypeError: must be str, not int

>>> "lala|helo".split(1)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: must be str or None, not int

>>> 1 in "lala"
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'in ' requires string as left operand, not int

>>> "lala|helo".split(object())
Traceback (most recent call last):
  File "", line 1, in 
TypeError: must be str or None, not object

--
components: Interpreter Core
messages: 393473
nosy: miguendes
priority: normal
severity: normal
status: open
title: Improve string's __getitem__ error message
type: enhancement
versions: Python 3.10, Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com