Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue14739] Add PyArg_Parse format unit like O& but providing context

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

May 7, 2012, 2:35 AM

Post #1 of 5 (104 views)
Permalink
[issue14739] Add PyArg_Parse format unit like O& but providing context

New submission from Larry Hastings <larry [at] hastings>:

If you write a PyArg_Parse "converter", and your conversion hits an error, you must raise an exception and error out. But, since your converter has no context about the parameter, it can't provide any helpful information in the error.

For example, PyUnicode_FSConverter attempts to convert a PyUnicode object to a PyBytes object; if it gets back some other kind of object, it calls
PyErr_SetString(PyExc_TypeError, "encoder failed to return bytes");
What parameter did this happen with? When calling what function? The hapless programmer is forced to guess.

In practice, the argument parser generally knows the name of the function and the name of the parameter. It'd be nice to encode those values in the error. But that information isn't passed in to the converter.

I propose adding a new format unit, let's call it 'O%', which is identical to 'O&' except for the signature of the converter function:

int converter(PyObject *o, void *p, PyConverterContext_t *context);

where PyConverterContext_t is defined as

typedef struct {
char *function_name;
char *parameter_name;
} PyConverterContext_t;

If the function name or parameter name is not known, it will be NULL.

----------
messages: 160125
nosy: larry
priority: normal
severity: normal
status: open
title: Add PyArg_Parse format unit like O& but providing context

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14739>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 7, 2012, 2:35 AM

Post #2 of 5 (100 views)
Permalink
[issue14739] Add PyArg_Parse format unit like O& but providing context [In reply to]

Changes by Larry Hastings <larry [at] hastings>:


----------
assignee: -> larry

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14739>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 7, 2012, 2:36 AM

Post #3 of 5 (103 views)
Permalink
[issue14739] Add PyArg_Parse format unit like O& but providing context [In reply to]

Changes by Larry Hastings <larry [at] hastings>:


----------
components: +Interpreter Core
stage: -> needs patch
type: -> enhancement

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14739>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 7, 2012, 3:00 AM

Post #4 of 5 (106 views)
Permalink
[issue14739] Add PyArg_Parse format unit like O& but providing context [In reply to]

Serhiy Storchaka <storchaka [at] gmail> added the comment:

It would be better if the functions PyArg_Parse* were wrapped converter's exception, in other exception with adding the names of function and parameter in the message. This will save us from necessity of the introduction of the new interface and immediately give effect to the old code.

----------
nosy: +storchaka

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14739>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

May 7, 2012, 3:45 AM

Post #5 of 5 (100 views)
Permalink
[issue14739] Add PyArg_Parse format unit like O& but providing context [In reply to]

Changes by Georg Brandl <georg [at] python>:


----------
nosy: +georg.brandl, loewis

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14739>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.