[C++-sig] object().attr_allow_null()

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Sat Jul 20 20:56:00 CEST 2002


--- David Abrahams <david.abrahams at rcn.com> wrote:
> How would you do it in Python?
> 
>     getinitargs = getattr(obj, '__getinitargs__', None)
> 
> in C++:
> 
>     object getinitargs = getattr(obj, "__getinitargs__", object());

Oh, I didn't know that getattr() can take three arguments. That's great!
 
> > So couldn't
> >
> > handle<>(obj.attr())
> >
> > be made to do exactly what I want?
> 
> That's cute, but probably not worth the complexity. Getting the object
> conversions to work right wasn't easy. I'll consider a patch, though.

I'll take the B for effort and use getattr().

>      if (!getinitargs) // for most cases you care about, this is OK

I was thinking "most" is not good enough for you.
This does not distinguish between None and and an empty tuple or dict,
does it?

>      if (is(getinitargs,object())) // otherwise...

Isn't this expensive, both in terms of code generated and performance wise?
And it doesn't look like Python!
This leads me to

       if (!getinitargs.is_none())

Ralf


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com





More information about the Cplusplus-sig mailing list