Message133551
| Author |
torsten.becker |
| Recipients |
hkBst, jcea, r.david.murray, rhettinger, santoso.wijaya, torsten.becker |
| Date |
2011年04月11日.22:48:03 |
| SpamBayes Score |
0.0 |
| Marked as misclassified |
No |
| Message-id |
<1302562084.68.0.815813277112.issue11828@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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? |
|