Python bindings feature complete

Havoc Pennington hp at redhat.com
Fri Feb 11 19:26:07 PST 2005


On Fri, 2005-02-11 at 16:23 -0500, John (J5) Palmieri wrote:
> Ah, but in python you can do:
> foreach item in list:
>   print str(item)

If that's what you're doing with the list then you're basically saying
it's a "list of printable" (you could even just make it a list of
strings) - there's a common base class/interface in effect. That's fine.

If you're using isinstance() then I think it's bad code.
I suppose we're getting off-topic here though. The point I'm trying to
make is that *conceptually* for sane code you can map to a dbus type,
even though you can't know the conceptual type without introspection or
programmer-provided declarations.

> 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.

If you're using a list/tuple as a struct then yeah heterogeneous types
make sense, but then you've defined the type of item at each index in
advance. Similar to using a dict as a struct. In both of these cases we
should figure out a way to map to a dbus struct.

> 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. 

Right. We just have to add introspection support.

Your simplest start on this would be like owen's old corba-perl
bindings: support loading the introspection data from a file.

> > 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 ;-)

Yup that's cool.

Havoc




More information about the dbus mailing list