[lxml-dev] findall() returns an iterable instead of a sequence in ET 1.3
Stefan Behnel
stefan_ml at behnel.de
Thu Sep 13 11:04:24 CEST 2007
Hi Fredrik,
I just noticed the above when I tried to copy over the new ElementPath
implementation from the current ET 1.3 SVN. The current ET docs of 1.2 clearly
state that findall() returns a sequence. I'm not questioning the new
behaviour, but it's not even mentioned in your "ET 1.3 intro" text. Don't you
think that change will break a lot of code out there?
It already breaks a couple of places in lxml.html, e.g. code where the author
knew that there were few results to expect (and thus a list was the perfect
thing to return) and where it is was convenient to test for the truth value of
the returned list to check for results.
Admittedly, it's easy to write list(el.findall()), but the thing is: a)
someone has to do that, and b) it's not always the best solution, so the
change requires people to rethink their code. And the worst is: you will not
even get an exception in all cases, as "if result" will simply behave
differently and your code after that may still work - just not as expected.
That's a pretty heavy change IMHO.
Stefan
More information about the lxml-dev
mailing list