[issue11828] startswith and endswith don't accept None as slice index

Torsten Becker report at bugs.python.org
Tue Apr 12 00:48:04 CEST 2011


Torsten Becker <torsten.becker at gmail.com> added the comment:

While working on this, I discovered anther problem.  find(), etc. all use the same parsing function (_ParseTupleFinds()).  So when an error occurs, the exception message will always start with "find()" even though index() or rfind() might have caused the error:

>>> "asd".index("x", None, None, None)
TypeError: find() takes at most 3 arguments (4 given)

I attached a patch (issue-8282-error-message-tests.patch) which adds test cases for the wrong error messages.

I was thinking about fixing this as well but wanted make sure my approach is correct first:

  - I would like to add another argument to _ParseTupleFinds(): const char * function_name
  - in _ParseTupleFinds(): allocate a buffer of 50 chars on the stack to hold "O|OO:" + function name
  - copy "O|OO:" into buffer
  - copy max(strlen(function_name), 44) chars from function_name into buffer
  - use buffer as format argument of PyArg_ParseTuple()
  - change all calls of _ParseTupleFinds to include the function name as first argument

Would that approach work with Python's C style or are there any Python-specific helper functions I could use?

----------
Added file: http://bugs.python.org/file21623/issue-8282-error-message-tests.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11828>
_______________________________________


More information about the Python-bugs-list mailing list