GNOME Bugzilla – Bug 508352
findChildren in tree.py needs a 'if children' check
Last modified: 2008-01-09 18:54:50 UTC
Please describe the problem: In findChildren, when children is None then we get TypeError. This is manifested in case of HyperLinks (directly?) under the node. I am using python-dogtail 0.6.1-3ubuntu2 on ubuntu gutsy. Steps to reproduce: 1.Open firefox and then any page with hyperlinks. 2. Run the following in script or python prompt : from dogtail import * print tree.root.findChild(predicate.GenericPredicate(roleName='menu',name='Applications')).findChildren(predicate.GenericPredicate(roleName='menu item')) print tree.root.findChildren(predicate.GenericPredicate(roleName='menu')) Actual results: The first call works. The second one gives "TypeError: 'NoneType' object is not iterable" Expected results: The check given below solves the issue, >> if children : for child in children: if child.satisfies(pred): selfList.append(child) if recursive: ... I am not sure if it's the best approach or whether we should cover it in getattr in Node class. As this problem seems to have slipped through somehow it would be better to put in a check anycase. (Also, see "# Somehow, if we allow the children to be seen, things get weird." comment in class Link) Does this happen every time? Yes Other information: A similar check might be required in dump.py. However even in this case when I do a tree.root.dump() even with the 'if node.children' check introduced in function 'plain', I get the following :
+ Trace 184704
wrt above, I saw that only the Base class has as assertion, the others here raise an AttributeError. Should it be changed ?
Thus bug is fixed in svn. The new behavior (not sure why this wasn't always done) is that node.children will be [] instead of None if there are no children. Therefore iterating over children will be a no-op instead of a TypeError.