Open ferdnyc opened 5 months ago
(Actually etree doesn't like having <?xml version="1.0"?>
at the start of the string, so I took that out. This way, it parses without issue.)
Seems like we should eliminate our lxml
stubs and point people to https://github.com/lxml/lxml-stubs, or https://github.com/abelcheung/types-lxml may actually be preferred.
I just ran into this issue as well. Thanks to OP for such a great write-up of the problem and rundown of what's going on.
Environment data
Code Snippet
Borrowing a chunk of Microsoft's own sample XML file...
Repro Steps
etree.fromstring(s)
callExpected behavior
The syntax is considered correct.
Actual behavior
Pylance's complaint is: Argument missing for parameter "parser"
Logs
I don't get the impression there's anything actually useful here, but...
Additional information
The issue appears to be that the type hints bundled with Pylance — in the extension's folder,
dist/bundled/native-stubs/lxml/etree.pyi
— are simply incorrect. Many of the hints are at odds with the function descriptions found right beneath them in the functions' docstrings. Forfromstring
, for example, the file contains:It's missing the
base_url
parameter entirely, and doesn't indicate that theparser
parameter has a default value, which is the cause of the incorrect annotation.fromstring
is far from the only mistyped function in the file.I don't know if it's because
lxml.etree
is implemented in Cython, but I do know that thefromstring
function signature hasn't changed in 17 years.Installing the external lxml stubs with
python3 -m pip install lxml-stubs
makes the error go away, because in those stubs thefromstring
function is typed like so: