Issue 12381: refactor slice checks made by methods that take "slice like" arguments (original) (raw)

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 "", line 1, in 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 "", line 1, in 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 "", line 1, in 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 "", line 1, in 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 "", line 1, in 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:18

admin

set

github: 56590

2011-07-27 10:35:58

petri.lehtinen

set

status: open -> closed
resolution: not a bug
messages: +

2011-07-17 08:54:26

anand.jeyahar

set

nosy: + anand.jeyahar
messages: +

2011-06-25 09:05:56

mark.dickinson

set

nosy: + mark.dickinson

2011-06-24 21:59:38

r.david.murray

set

title: 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: +
versions: - Python 2.7, Python 3.2

2011-06-21 18:33:30

petri.lehtinen

set

nosy: + petri.lehtinen

2011-06-21 13:17:39

xuanji

set

nosy: + xuanji

2011-06-21 13:00:28

r.david.murray

set

versions: + Python 3.2, Python 3.3, - Python 3.1
nosy: + r.david.murray

messages: +

keywords: + easy

2011-06-21 03:57:16

py.user

create