Friday, October 22, 2021

Completion with python extension modules such as PyQt5 and Pandas

Code Completion in the editor when you are using python extension modules has always been hard, primarily because these are not implemented in python code but rather in a compiled language (typically C) and come as dynamic link libraries.  PyScripter in the past the option to import such modules when code completion was requested and used introspection of the imported modules to provide code completion and general IntelliSense support.

With the implementation of the Language Server Protocol and the inclusion of the Jedi language server there is now a better option. The use of stubs described in PEP 484.

pip install PyQt5-stubs

You would use the pip external Tool for installing the stubs.  Then restart the language server, using the command under the Tools menu and presto,  you have near perfect code completion with PyQt5.

Many packages such as numpy come with their stubs included.  For others you can in internet for stub support.

Another way to improve code completion is to add the package/module name to the list of “Special packages” in the IDE options under code completion.  Jedi will load these modules and this in many cases can improve the speed and quality of code completion.  This works well with the pandas library for example.

 

No comments: