GNOME Bugzilla – Bug 328318
Nodes without children return an exception when you get children property
Last modified: 2006-04-13 14:26:07 UTC
Please describe the problem: Suppose you have a node without children, and you try to get its children, with a call like "node.children". If this node hasn't got any children, it returns an AttributeError exception. The expected behaviour is returning an empty list, I think. Steps to reproduce: 1. Get a node without children 2. Try to get the property children Actual results: You get an AttributeError exception in get_attr. Expected results: You should get an empty list. Does this happen every time? Yes Other information: The problem is in the __get_attr__ method of Node (see tree.py). For the "children" case, it tries to add the children to the list. If the list remains empty (as in the case it's empty), it raises the exception, when it should return the empty list.
Thanks for reporting this. The current behavior is longstanding, but has annoyed me for a while. I've been wanting to change it (and will, now that i know someone else is bothered by it), but it will mean substantial changes to code that depends on that behavior. It will probably have to wait until after 0.5.0.
I've just committed a large patch to remove dogtail.tree's use of AttributeErrors in cases where the attribute exists, but doesn't apply to that particular Node instance. A node with no children will have an empty list as that attribute, and a node with no AccessibleText interface will have None as its text attribute.