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

"etree" is unknown import symbol (lxml) #392

Closed
cebor opened this issue Sep 18, 2020 · 7 comments
Closed

"etree" is unknown import symbol (lxml) #392

cebor opened this issue Sep 18, 2020 · 7 comments
Assignees
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version needs stub

Comments

@cebor
Copy link

cebor commented Sep 18, 2020

Environment data

  • Language Server version: 2020.9.5
  • OS and version: macOS 10.15.6 (19G2021)
  • Python version (& distribution if applicable, e.g. Anaconda): python3.8 (venv)

Actual behaviour

I use the library lxml:4.5.2 and getting following error while importing, also autocomplete is not working. (https://lxml.de/)

from lxml import etree
"etree" is unknown import symbol Pylance (reportGeneralTypeIssues)

With language server set to jedi all is working fine.

@jakebailey
Copy link
Member

lxml's etree module appears to be compiled, so we can't get any information out of it as there's no source to read (and we currently don't have a scraper to attempt to load the module and inspect it at runtime). At the moment, the best solution would be to have a set of stubs for lxml (as it appears to be almost entirely compiled code).

Note that reportGeneralTypeIssues only appears if your type checking mode is set to something other than "off", and off is the default for Pylance.

@cebor
Copy link
Author

cebor commented Sep 18, 2020

Installing the correct stubs fixed it for me, thanks for the hint.

https://github.com/lxml/lxml-stubs

pip install lxml-stubs

@huguesv
Copy link
Contributor

huguesv commented Sep 18, 2020

Pylance is able to make use of stubs packages, and there is one available for lxml: pip install lxml-stubs

It might work okay. I don't get any error on this simple code (in basic type checking mode):

image

@jakebailey
Copy link
Member

Thanks for the tip; I didn't realize those had existed in typeshed but had been removed. We might be able to bundle them as we do with a few other commonly used libraries if lxml is common enough.

@ssbarnea
Copy link

I fact I suspect pylance ability to import submodules is partially broken because I see similar errors when importing submodules from my own package. Neither mypy, pylint or flake8 complain about them but pylance wrongly produces them.

@jakebailey
Copy link
Member

jakebailey commented Nov 30, 2020

This issue is about lxml.etree not having any members; we have resolved this in the last release via special compiled coded stubs.

@ssbarnea If you're having issues resolving imports, then please file a new issue as this issue is different. I'd be interested to see if downgrading Pylance fixes your issue.

@heejaechang heejaechang self-assigned this Mar 31, 2021
@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Apr 1, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.4.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202140-7-april-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version needs stub
Projects
None yet
Development

No branches or pull requests

5 participants