Pylance-release: intellisesne isn't working with .pyc modules

Created on 14 Aug 2020  路  8Comments  路  Source: microsoft/pylance-release

Environment data

  • Language Server version: 2020.8.1

  • OS and version: Windows 10
  • Python version: Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
  • Expected behaviour

    When provided path to folder containing .pyc files in setting python.analysis.extraPaths intellisense should provide list of methods for modules in that folder.

    Actual behaviour

    Intellisense isn't able to resolve compiled modules (.pyc). It shows error -> Import "hello" could not be resolvedPylance (reportMissingImports). On based of reading else where I was under the impression that pylance can scrap info from .pycs to provide intellisense. Please correct me if I am wrong. I am using following command to compile

    python.exe -m compileall -b ..libraryhello.py

    I am attaching pseudo code intellisesne_pyc.zip. This folder contains workspace folder and library folder. The code in workspace folder imports module in library folder that is compiled. I hope this helps.

    intellisesne_pyc.zip

    compiled needs investigation

    All 8 comments

    Pylance cannot read info from compiled modules, no. Compiled code currently requires a stub to work, and we will not try and execute the compile code to learn of its contents. Note that MPLS didn't do this either for user code, but would for libraries.

    Pylance does not attempt to extract type information from binary files. The interface to native files needs to be described with a type stub ("pyi") file. Many library authors are now providing such stubs with the latest versions of their packages, so please check that you have the latest version installed. If the latest version of the library is missing the stub, I encourage you to submit a request to the library author.

    Thank you for the quick reply. I am the library author and was experimenting with VS code configuration as if I am the user of library. We are already generating pyi files for pyds. We are using pybind11 tools to do that. I was expecting pyc to work out of the box. I will look into tools to generate pyi file. Please let me know if you have any recommendations.

    166 has a similar discussion. Producing stubs from the pyc files isn't advisable as they don't really contain the right kind of info. You may have a better experience writing the pyi files directly (this is what is being done in numpy, torch, etc), but I'm not sure what the size of your project is.

    Pylance cannot read info from compiled modules, no. Compiled code currently requires a stub to work, and we will not try and execute the compile code to learn of its contents. Note that MPLS didn't do this either for user code, but would for libraries.

    @jakebailey I got wrong impression because this comment https://github.com/microsoft/python-language-server/issues/1081#issuecomment-498068163. When I read that comment again I think it was in context of Jedi LS. Probably it works with Jedi?

    As far as I know, Jedi does not enable its "scraper" mode by default, and requires user configuration to allow it.

    Investigating solutions for compiled modules

    a new repo for stub is available at python-type-stubs. This is open for contributions. Snapshots from here will be periodically shipped with Pylance.

    This is the place to add stubs for compiled modules. As mentioned above, Pylance will not scrape compiled modules.

    Was this page helpful?
    0 / 5 - 0 ratings