bpo-30485: Change the prefix for defining the default namespace in ElementPath from None to '' by scoder · Pull Request #12860 · python/cpython (original) (raw)

I was considering allowing both in ET as well (and implemented it along the way), but decided against it because a) the implementation is quite ugly, b) there are probably not that many users who go from lxml to ET, and c) ET's API generally has almost no exposure of prefixes whatsoever, so it doesn't matter there. Using prefixes in ElementPath expressions is not even the recommended way, because self-contained string expressions with explicit "{ns}tag" notation are much nicer to handle overall.

lxml, on the other hand, returns a dict with None as prefix when you let it collect the namespaces defined on an Element and its parents (nsmap), so not supporting both there would be unnatural, and changing this is essentially impossible. At least for now, I think it's ok to support only the simpler (and more convenient) empty string in ElementTree, and I also don't see lxml deprecate or remove support for None as prefix. Adapting the docs should fix it over time.