Eli Bendersky added the comment:

Hi Nick,

I disagree with this change. The way the APIs are currently defined, XMLParser 
and XMLPullParser are different animals. XMLParser can be considered to only 
have one "front" in the API - feed() and close(). You feed() until the document 
is done and then you close() and get the parsed tree. There's no other way to 
get the parsed tree (unless you use a custom builder, I guess).

On the other hand XMLPullParser has two clear "fronts" - an input front with 
feed() and close() and an output front with read_events(). For XMLPullParser, 
close() is just an input signal. The canonical way to get output from 
XMLPullParser is read_events(). close() has no better reason to return output 
than feed(). When we decided to change the method names (recall that Antoine's 
originals were completely different), we perhaps forgot this detail. Even 
though XMLPullParser's method is named close(), it's *not* like XMLParser's 
close(). If someone is using XMLPullParser for its close() he's likely using 
the class incorrectly.

Just as an example: consider that in a lot of use cases the programmer will 
want to discard parts of the tree that's parsed iteratively (similarly to the 
main use case of iterparse()), because the XML itself is too huge. It's a 
convenient streaming API, in other words. Now, if the reader discards parts of 
the tree (by deleting subtrees), then returning the root from close() becomes 
even more meaningless, because it's no longer the root and we have no idea what 
it actually is.

Finally, I will add that we can always err on the side of under-specifying. We 
plan to change the implementation of the class in the future, so we can always 
add to the API. Specifying that close() returns the root is something we can't 
back out of, but we can always add in a future release without hurting 
backwards compatibility, if we do reach the conclusion that it's better.

---

P.S. all of this makes me wonder if we should mark the API of XMLPullParser 
provisional for 3.4

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18990>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to