Ivan Vilata i Balaguer wrote:

En/na Andrew Straw ha escrit::

Hmm... I still think it's a bug if getattr works but delattr fails by
raising an AttributeError. Some other kind of error would at least be
more understandable for setattr and delattr. I mean, the attribute
exists -- I can get it -- I just can't set it or delete it. So maybe a
TypeError or an AttributeNotModifiableError or something.
[...]

Hi Andrew, the exception you got and the behaviour you observed is
intentional.  Group.__delattr__() does not remove children nodes because
it would be prone to accidental removal of whole subtrees.  It only
removes standard Python attributes.  That's why you got an error (there
was no standard Python attribute called *group*).

Natural naming is just a help for comfortably getting to nodes during
interactive, command-line sessions, and that's why it is only concerned
with Group.__getattr__().  __setattr__() and __delattr()__ are only
concerned with standard Python attributes, so you would be setting and
deleting standard attributes, not child nodes.  To sum it up:

1. Group.__setattr__() always sets a Python attribute.
2. Group.__getattr__() gets a Python attribute, if available.  Else, it
  gets a child node.
3. Group.__delattr__() always deletes a Python attribute.
Hi Ivan (and Francesc), thanks for your responses on this (on my other!) issues... You are very helpful, as always.

I understand the logic well enough. My point is that it's simply very confusing that a child node sometimes counts as an attribute (getattr) and sometimes does not (setattr, delattr). I can live with the issue now that I understand it. My suggestion is meant to help those with less understanding of PyTables than I now have (me 3 days ago would be an example of such a person). It seems to me that __setattr__ and __delattr__, before raising an AttributeError, could at least check if there's a child node by the name and raise something other than an AttributeError (ChildNodeIsNotPythonAttributeError even, if you like.) I think the performance penalty would be negligible (it's only in an error-path) and the clarity benefit would be significant.


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to