[Python-Dev] new property factory arguments (original) (raw)

M.-A. Lemburg mal@lemburg.com
Mon, 18 Feb 2002 12:17:17 +0100


john coppola wrote:

Hello python developers. After discussions with Fred about defining how property objects are created, I decided to give it a whirl myself. After about minute of piddling, I came up with something I thought would be a hack but is quite interesting. ... ! propertyinit(PyObject *self, PyObject *args, PyObject *kwds) { ! PyObject *get = NULL, *set = NULL, *del = NULL, *doc = NULL; ! static char *kwlist[] = {"fget", "fset", "fdel", "doc", 0}; ! propertyobject *gs = (propertyobject *)self; ! ! if (!PyArgParseTupleAndKeywords(args, kwds, "|OOOO:property", ! kwlist, &get, &set, &del, &doc)) ! return -1; ... --- 1003,1023 ---- } static int ! propertyinit(PyObject *self, PyObject *args, PyObject *kw) { ! PyObject *get=NULL, *set=NULL, *del=NULL, *doc=NULL, *arg=NULL; ! static char *kwlist[] = {"object", 0}; ! propertyobject *gs = (propertyobject *)self; ! if (!PyArgParseTupleAndKeywords(args,kw,"|O:property",kwlist,&arg)) ! return -1; ! ! get = PyObjectGetAttrString(arg,"get"); ! set = PyObjectGetAttrString(arg,"set"); ! del = PyObjectGetAttrString(arg,"del"); ! doc = PyObjectGetAttrString(arg,"doc");

Wouldn't this break the documented API ?

If so, I'd suggest to provide a second constructor which exposes the new signature instead. Should be easy to do in Python...

-- Marc-Andre Lemburg CEO eGenix.com Software GmbH


Company & Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/