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

default namespace in find method #60

Closed
cukiernick opened this issue Sep 4, 2024 · 1 comment
Closed

default namespace in find method #60

cukiernick opened this issue Sep 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@cukiernick
Copy link

Currently namespaces type in find method is defined as _StrictNSMap = Mapping[str, str], which causes mypy error being reported when default namespace (None key) is used. Is it correct?
lxml supports 2 ways of specifying the default namespace: None and an empty string (""). Because nsmap attribute of Element shows the default namespace under None key, I'd expect find to also be allowed to use this format.

Small snippet from ipython:

In [13]: z = lxml.etree.XML("<a><b xmlns='foo'/></a>")

In [14]: z.find('./b')

In [15]: z.find('./b', namespaces={None: "foo"})
Out[15]: <Element {foo}b at 0x7f6df2c0e480>

In [16]: z.find('./b', namespaces={"": "foo"})
Out[16]: <Element {foo}b at 0x7f6df2c0e480>

In [17]: z.find('./b', namespaces={"": "foo"}).nsmap
Out[17]: {None: 'foo'}
@abelcheung
Copy link
Owner

You're correct, I have been overzealous with the namespaces dict key change. Originally it is intended to prevent silly usage like find('*', namespaces={None: "foo", "": "bar"}), but such corner cases hurts more general usage. Will fix it soon.

@abelcheung abelcheung added the bug Something isn't working label Sep 4, 2024
@abelcheung abelcheung moved this to In Progress in Types-lxml progress Sep 4, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Types-lxml progress Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants