Python bindings feature complete

John (J5) Palmieri johnp at redhat.com
Fri Feb 11 13:23:00 PST 2005


On Fri, 2005-02-11 at 15:56 -0500, Havoc Pennington wrote:
> On Fri, 2005-02-11 at 15:17 -0500, John (J5) Palmieri wrote:
> > * Recursive types are stuck with restrictions of the C api such as all
> > array and dict elements must be of the same type.
> 
> Even in dynamic languages IMO it's sort of crackrock to store multiple
> types in one container. (Where "multiple types" means you do RTTI;
> multiple subclasses of one base class is cool)
> 
> In other words this is a bad hack even in python:
>  
>  foreach item in list:
>    if isinstance (item, str):
>      pass
>    elif isinstance (item, integer):
>      pass

Ah, but in python you can do:
foreach item in list:
  print str(item)

For the most part this is not the problem anyway since tuples act like
structs and can have dynamic types for each value.  The main point is
that python lets you assign whatever to a list so it is wierd for a
python programmer to have to understand new rules when using dbus.

> You get the point.
> 
> For dicts it's more OK but the usual case is that it's defined which
> type the value for a given key will have and the type of dict is
> dict<something,variant>
>
> So then you avoid the isinstance() by knowing the key.

This is where I was really concerned. I guess I could just implement
dicts in python as dict<something, variant> which is how I ported the
HAL hashes.  The biggest problem is that if a C program is expecting a
dict of string values python is screwed.  Since no C programs currently
use dicts as input it might be good to say screw it and just use the
variants.  Once the python bindings gets dbus introspection and most C
programs are written using glib or other high level bindings that export
introspection data things will be grand.  Note these issues are only
with sending data structures as python can dynamically marshal any
combination of data types received over the wire. 


> > * Optimizing signature creation.  Right now when we need to get a
> > signature of a container's children we recurse all the children.  This
> > is done each time we need the signature, whether or not we have
> > traversed the children already for a higher level container.  For
> > example a data structure of signature aaai would recurse three times:
> > 
> > aai
> > ai
> > i
> 
> Probably isn't really that slow once you consider all the other stuff
> that's going on.
> 
> > In order to work with some applications which send variable length
> > parameter lists instead of sending a list as one of the parameters
> > (*cough*Hal*cough*) 
> 
> I think HAL is just busted here now that we have array of variant. Lots
> of bindings won't be able to handle this.

I plan on fixing this when I get the time but supporting the old way of
handling signals wasn't all that hard and didn't complicate the code
much.  I had to be just a little nice to those who have to do the
porting because, well, I'm one of the ;-)

-- 
John (J5) Palmieri
Associate Software Engineer
Desktop Group
Red Hat, Inc.
Blog: http://martianrock.com



More information about the dbus mailing list