[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 018fe1dee9b3 by Petri Lehtinen in branch 'default': What's new: Add myself as the contributor of issue 12170 http://hg.python.org/cpython/rev/018fe1dee9b3 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 75648db1b3f3 by Victor Stinner in branch 'default': Issue #13623: Fix a performance regression introduced by issue #12170 in http://hg.python.org/cpython/rev/75648db1b3f3 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
STINNER Victor victor.stin...@haypocalc.com added the comment: New changeset 75648db1b3f3 by Victor Stinner in branch 'default': http://hg.python.org/cpython/rev/75648db1b3f3 Issue #13623: Fix a performance regression introduced by issue #12170 in bytes.find() and handle correctly OverflowError (raise the same ValueError than the error for -1). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Antoine Pitrou pit...@free.fr added the comment: Just a thought: Would this change be worthy for the What's new in 3.3 list? I think so. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset 736b0aec412b by Petri Lehtinen in branch 'default': Add a What's New entry for #12170 http://hg.python.org/cpython/rev/736b0aec412b -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Petri Lehtinen pe...@digip.org added the comment: Just a thought: Would this change be worthy for the What's new in 3.3 list? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset c1effa2cdd20 by Antoine Pitrou in branch 'default': Issue #12170: The count(), find(), rfind(), index() and rindex() methods http://hg.python.org/cpython/rev/c1effa2cdd20 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Antoine Pitrou pit...@free.fr added the comment: Patch committed, thank you! -- assignee: rhettinger - resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Petri Lehtinen pe...@digip.org added the comment: Thanks for the review, Antoine. Attached an updated the patch: - The function definition now uses STRINGLIB(...) and the function is only defined when !STRINGLIB_IS_UNICODE (so I took both approaches) - Added a versionadded:: 3.3 to the documentation. -- Added file: http://bugs.python.org/file23464/issue12170_v2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Changes by Petri Lehtinen pe...@digip.org: Removed file: http://bugs.python.org/file23464/issue12170_v2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Petri Lehtinen pe...@digip.org added the comment: Fixed a minor inconsistency. -- Added file: http://bugs.python.org/file23465/issue12170_v2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Antoine Pitrou pit...@free.fr added the comment: I made the decision to raise a ValueError decision because __contains__ of both bytes and bytearray raise a ValueError when passed an integer not in range(0, 256). That sounds reasonable. OverflowError would have been another choice, but I agree that consistency with __contains__ is sensible. -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Antoine Pitrou pit...@free.fr added the comment: Doc/library/stdtypes.rst needs a versionadded tag for the additional semantics. Also, the patch doesn't compile fine on current default: In file included from Objects/unicodeobject.c:487:0: Objects/stringlib/find.h: In function ‘stringlib_parse_args_finds_byte’: Objects/stringlib/find.h:158:5: attention : implicit declaration of function ‘stringlib_parse_args_finds’ In file included from Objects/unicodeobject.c:497:0: Objects/stringlib/find.h: Hors de toute fonction : Objects/stringlib/find.h:151:1: erreur: redefinition of ‘stringlib_parse_args_finds_byte’ Objects/stringlib/find.h:151:1: note: previous definition of ‘stringlib_parse_args_finds_byte’ was here I'd say you need to either define your function as STRINGLIB(parse_args_finds_byte) (to avoid name collisions), or avoid defining it if STRINGLIB_IS_UNICODE. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Changes by Florent Xicluna florent.xicl...@gmail.com: -- nosy: +flox ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Raymond Hettinger raymond.hettin...@gmail.com added the comment: See also #12631 regarding the remove() method for bytearray. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Petri Lehtinen pe...@digip.org added the comment: See also #12631 regarding the remove() method for bytearray. AFAICS, it's about bytearray.remove() working but bytearray.index() not working as documented, and that's why I marked is as a duplicate of this issue. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Petri Lehtinen pe...@digip.org added the comment: Ok, so the current raising semantics should be good. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Changes by STINNER Victor victor.stin...@haypocalc.com: -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Petri Lehtinen pe...@digip.org added the comment: Attached a patch with the following changes: Allow an integer argument in range(0, 256) for the following bytes and bytearray methods: count, find, index, rfind, rindex. Initially, only count and index were targeted, but as index is implemented in a helper function that is also used to implement find, rfind and rindex, these functions were affected too. The bytes methods were changed to use the new buffer protocol instead of the deprecated PyObject_AsCharBuffer, for consistency with the bytearray code. Tests for all the modified functions were expanded to cover the new functionality. While at it, the tests for count, index and rindex were also further expanded (to test for slices, for example), as they were initially quite minimal. A paragraph describing the additional semantics of the five methods was added to the documentation. The error messages of index and rindex were left untouched (substring not found and subsection not found). In a case where the first argument is an integer, the error messages could talk about a byte instead of substring/subsection. This would have been a bit non-straightforward to implement, so I didn't. The docstrings were also left unchanged, as I couldn't find a good wording for them. The problem is not that the first argument may now be an integer, but as it can now be more than a substring or subsection, we might have to specify what a substring or subsection really means. And that explanation would be lengthy (because of the buffer protocol, that's not a concept that a regular Python programmer is, or even needs to be, familiar with)... And finally, there's one thing that I'm unsure of: When an integer out of range(0, 256) is passed as the first argument, should we raise a ValueError or a TypeError? Currently, a ValueError is raised, but this may be bad for index and rindex, as they raise a ValueError when the substring or byte is not found. I made the decision to raise a ValueError decision because __contains__ of both bytes and bytearray raise a ValueError when passed an integer not in range(0, 256). -- keywords: +needs review, patch stage: test needed - patch review Added file: http://bugs.python.org/file22733/issue12170.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Ezio Melotti ezio.melo...@gmail.com added the comment: When an integer out of range(0, 256) is passed as the first argument, should we raise a ValueError or a TypeError? ValueError = Inappropriate argument value (of correct type). TypeError = Inappropriate argument type. Currently, a ValueError raised, but this may be bad for index and rindex, as they raise a ValueError when the substring or byte is not found. Then the users should check if the value is in range(256) before passing it to (r)index. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12170] index() and count() methods of bytes and bytearray should accept byte ints
Petri Lehtinen pe...@digip.org added the comment: This affects bytearray as well as bytes. What comes to supporting integer argument to str methods, I'm -1 on that. str's contained items are strings of length 1. -- title: Bytes.index() and bytes.count() should accept byte ints - index() and count() methods of bytes and bytearray should accept byte ints versions: -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12170 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com