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.

classification
Title: refactor slice checks made by methods that take "slice like" arguments
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: anand.jeyahar, mark.dickinson, petri.lehtinen, py.user, r.david.murray, xuanji
Priority: normal Keywords: easy

Created on 2011-06-21 03:57 by py.user, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg138770 - (view) Author: py.user (py.user) * Date: 2011-06-21 03:57
>>> bytearray(b'abc').count(bytearray(b''), None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method
>>> bytearray(b'abc').find(bytearray(b''), None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method
>>> bytearray(b'abc').index(bytearray(b''), None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method


and duplicate issues (endswith and startswith):

>>> bytearray(b'abc').endswith(bytearray(b''), None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method
>>> bytearray(b'abc').startswith(bytearray(b''), None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method
>>>
msg138785 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-21 13:00
As Raymond said in another issue, someone should fix this once and for all by factoring this check out into a reusable method and making sure it is used everywhere.
msg138994 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-24 21:59
Note that both of these have been fixed in default, so I'm repurposing this issue for the refactoring I suggested.  However, since I can't find an existing issue for the bytearray fix, maybe somebody already did it and I didn't notice.
msg140519 - (view) Author: anand jeyahar (anand.jeyahar) Date: 2011-07-17 08:54
I started working on this. But found sliceobject.c. Think it would be a good idea to add the refactored functions there. Anyway, i was trying to figure out the functionality of sliceobject.c. Can someone put up a use/test case example for it? Thanks for patience with my newbieness to python source
msg141217 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-07-27 10:35
R. David Murray wrote:
> Note that both of these have been fixed in default, so I'm
> repurposing this issue for the refactoring I suggested.
> However, since I can't find an existing issue for the bytearray
> fix, maybe somebody already did it and I didn't notice.

It seems to me that such refactorization has been already done when fixing issue 11828. The stringlib_parse_args_finds() function is used to to parse the slice-like arguments of str, bytes and bytearray functions.

As the errors reported in the issue have already been fixed in all branches, I'm closing this as invalid.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56590
2011-07-27 10:35:58petri.lehtinensetstatus: open -> closed
resolution: not a bug
messages: + msg141217
2011-07-17 08:54:26anand.jeyaharsetnosy: + anand.jeyahar
messages: + msg140519
2011-06-25 09:05:56mark.dickinsonsetnosy: + mark.dickinson
2011-06-24 21:59:38r.david.murraysettitle: bytearray methods count, find, index don't support None as in slice notation -> refactor slice checks made by methods that take "slice like" arguments
messages: + msg138994
versions: - Python 2.7, Python 3.2
2011-06-21 18:33:30petri.lehtinensetnosy: + petri.lehtinen
2011-06-21 13:17:39xuanjisetnosy: + xuanji
2011-06-21 13:00:28r.david.murraysetversions: + Python 3.2, Python 3.3, - Python 3.1
nosy: + r.david.murray

messages: + msg138785

keywords: + easy
2011-06-21 03:57:16py.usercreate