Python API pyi files for autocompletion and type checking in external editors

Python interface definition stubs / modules (.pyi files) are a standardized way to describe API that is accessible from Python, but not implemented as Python code. They can contain type information which advanced Python editors like Visual Studio Code with the Python extension can utilize to provide very smart auto-completion and static type checking.

I have produced / generated full pyi definition for VC 4.8 Premium’s API based on the new online help.

Here is a (silent) demo of using these with Visual Studio Code, using Pylance as type checker.

Features:

  • Includes all Python classes and their members (properties, methods, constructors, events) + constants as described in the online help.
  • Includes accurate type information where possible.
  • Includes descriptions and direct links to the online help.
  • Module organization is similar to VC. Functions from vcScript, vcCommand, vcVector etc. can be imported.

Caveats:

  • Definitions for some base classes such as vcBehaviour have to include properties that may only exist in some of the behaviours. These have a note in the description.
  • Type checkers don’t really support Python 2 anymore, so they will complain about print statements and assignments between types because casts can’t be used.
  • Dynamically created properties can’t be known so they are not included.

How to use with Visual Studio Code

  • Download and extract the pyi files to some convenient location.
  • Install VS Code, the Python extension and Pylance extension.
  • Add the pyi module folder to “python.autoComplete.extraPaths” and “python.analysis.extraPaths” settings of the Python extension.
  • Configure VC to use VS code as external Python editor.
  • Open Python scripts from VC, configure VS Code to trust the folder path to enable all editor features.
  • Enable type checking in VS code.

Download the files from here:

vcApi VC48.zip (146.6 KB)

12 Likes

This is awesome! I extracted the vcApi folder to my VC installation folder under Python - Commands. This is how I modified the Pylance settings and got it working.

4 Likes

Wow this is a game changer, thanks for sharing!

So after trying to get this to run on my new machine for several hours, I finally cracked it :slight_smile:

  1. First follow insctruction in the main post.
  2. Then if you are too lazy to read all that, drop the stuff into the intallation folder as depicted in @Este comment.
    2a) I past the string here so you do not need to replace all the slashes: “C:/Program Files/Visual Components/Visual Components Premium 4.8/Python/Commands/vcApi”
  3. THIS IS MY TRICK: Workspaces in Visual Studio Code , setting a workspace made the auto completion start. I just picked my C drive.
1 Like