-
Notifications
You must be signed in to change notification settings - Fork 29
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
NSMapArg type definition is incorrect. #76
Comments
I also just encountered this issue, and agree that the documentation disagrees with the type stubs. |
According to this comment: # See https://github.com/python/typing/pull/273
# Due to Mapping having invariant key types, Mapping[Union[A, B], ...]
# would fail to validate against either Mapping[A, ...] or Mapping[B, ...]
# Try to settle for simpler solution, encouraging use of empty string ('')
# as default namespace prefix. If too many people complain, it can be
# back-paddled as Mapping[Any, ...]
_NSMapArg = Mapping[str, str]
Which is fine by me, except it doesn't work: In [78]: etree.Element('{foo}test', nsmap={'': 'pr'})
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[78], line 1
----> 1 etree.Element('{foo}test', nsmap={'': 'pr'})
File src/lxml/etree.pyx:3092, in lxml.etree.Element()
File src/lxml/apihelpers.pxi:138, in lxml.etree._makeElement()
File src/lxml/apihelpers.pxi:125, in lxml.etree._makeElement()
File src/lxml/apihelpers.pxi:226, in lxml.etree._setNodeNamespaces()
File src/lxml/apihelpers.pxi:1746, in lxml.etree._prefixValidOrRaise()
ValueError: Invalid namespace prefix '' Apparently the empty string only works for the |
I am having exactly this problem as @danpascu as well. For now I'll have to settle with ignoring this ( |
nsmap
argument of Element function is of typeOptional[_NSMapArg]
where_NSMapArg
isMapping[str, str]
.But according to the documentation here namespace key for the default namespace supposed to be
None
:So it seems like
_NSMapArg
should beMapping[Optional[str], str]
The text was updated successfully, but these errors were encountered: