Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency regarding namespace mappings #62

Open
funkyfuture opened this issue Mar 23, 2022 · 0 comments
Open

Inconsistency regarding namespace mappings #62

funkyfuture opened this issue Mar 23, 2022 · 0 comments

Comments

@funkyfuture
Copy link
Contributor

by this comment i felt strongly encouraged refactor code in order to use an empty string as key for the default namespace in a namespace mapping, but soon found inconsistencies with the current annotations and implementation.

first, mypy complains about this:

an_element = etree.fromstring("<element/>")
a_new_element = an_element.makeelement("new", nsmap=an_element.nsmap)

with error: Argument "nsmap" to "makeelement" of "_Element" has incompatible type "Dict[Optional[str], str]"; expected "Optional[Mapping[str, str]]".

then, the empty string as key isn't even the default:

In [1]: from lxml import etree
In [2]: t = etree.fromstring("<element xmlns='test'/>")
In[3]: t.nsmap.get(None)
Out[3]: 'test'
In[4]: t.nsmap.get("")
Out[[4]:

i have no proposal how to solve these issues, but i consider the first demo a bug and the latter at least confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant