[SAGA-RG] SAGA attributes as Python dictionaries?

Andre Merzky andre at merzky.net
Wed Nov 4 10:06:28 CST 2009


Quoting [Mathijs den Burger] (Nov 04 2009):
> 
> Hi all,
> 
> For the Python language bindings, we (at the VU) are thinking about
> CCT's idea to use the Python 'dict' interface for SAGA attributes. While
> we like the idea to use Python-specific constructs in the language
> bindings, it seems that SAGA attributes differ in semantics from the
> 'associative arrays' that are Python's dictionaries.
> 
> Some examples where Python dicts and SAGA attributes differ:
> 
> 1. They throw different exceptions (e.g. KeyError vs BadParameter /
> PermissionDenied / DoesNotExist / AuthenticationFailed /
> AuthorizationFailed / BadParameter / IncorrectState / NoSuccess)

So, you say that the SAGA exceptions would be unexpected in those
places.  Good point, but I think its ok if the language binding
defines a mapping.  I also think that language native constructs are
appealing...


> 2. Removing SAGA attributes is permanent (AFAIK when talking to Ceriel),
> while a deleted dict item can be re-added latter

Not sure I undestand.  the following should be valid:

  if ( ! advert.attribute_exists ("foo") )
  {
    advert.set_attribute ("foo", "bar");
  }

  assert (advert.attribute_exists ("foo"), true);

  advert.remove_attribute ("foo");

  assert (advert.attribute_exists ("foo"), false);

  advert.set_attribute ("foo", "bar");

  assert (advert.attribute_exists ("foo"), true);

?


> 3. Dictionaries accept any hashable object, whereas SAGA attributes only
> accept a set of defined values.

Yes, thats a tough one.


> Exposing SAGA attributes as a dictionary may therefore lead to
> confusion, as the two are similar but not identical.

Which does not really help I guess.  

 
> Another option for easy access (which we use in our implementation on
> top of Java SAGA) is to use Python's 'property' construct for each
> defined attribute. This allows you to do, for example:
> 
> >>> from saga import job
> >>> js = job.JobDescription()
> >>> js.Executable = "/bin/date"
> >>> js.Arguments = [ "-R" ]
> 
> Python translates such property access to calling getter an setter
> functions that can do additional checking. Very flexible, and the syntax
> is even shorter than using the 'dict' interface. Wouldn't that be a
> better option for easy access to SAGA attributes in Python?

This has been discussed in Banff, but I can't remember the details
of the argumentation (I am no Pythoneer...).  

My notes say:

  attribute interface: possibly to ONLY set_attribute/get_attribute,
  even if that is not 100% Pythonesc.  SAGA attribs *are* *not*
  calls member attribs, but conveye a different semantics.  Also,
  they are sometimes extensible, sometimes not, sometimes readwrite,
  sometimes readonly - all difficult to express in the 'native' way
  it seems.  Not to speak of async...

Does that make sense to you?  Do you consider these arguments valid?

Best, Andre.


-- 
Nothing is ever easy.


More information about the saga-rg mailing list