-
Notifications
You must be signed in to change notification settings - Fork 30
Closed
Description
At least with lxml 4.8.0, I see the following:
$ python
Python 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml.etree as etree
>>> parser = etree.HTMLParser(recover=True, encoding="utf-8")
>>> tree = etree.fromstring(b"", parser)
>>> tree
>>> tree is None
True
But the type annotation says we'll always return an _Element
:
lxml-stubs/lxml-stubs/etree.pyi
Lines 498 to 500 in 5eaa0f8
def fromstring( | |
text: _AnyStr, parser: XMLParser = ..., *, base_url: _AnyStr = ... | |
) -> _Element: ... |
Aside: I'm passing an HTMLParser here instead of an XMLParser. The type stub for fromstring
doesn't allow that either, but again I'm not sure if that's a mistake in the annotations.
For context, I came across this whilst trying to use the stubs to typecheck this snippet of Synapse.
Metadata
Metadata
Assignees
Labels
No labels