Sublime Forum

Typing stubs for Sublime Text 3 API

#1

For my LSP plugin I wanted a way to verify that Sublime Text’s API was being used correctly while coding.

I found the mypy project, which provides both a linter and a stub generator.
Generating stubs on sublime.py and sublime_plugin.py resulted in incomplete stubs, which I manually completed.

Feel free to take these stubs from https://github.com/tomv564/LSP/tree/master/stubs for your own use. Is there a preferred way to distribute them?

If Jedi could eventually support these stubs, we will get good tools for autocompletion as well (see https://github.com/davidhalter/jedi/issues/839)

Are there some other ways to get completion or verification of the Sublime Text API outside of Sublime Text?

1 Like

#2

I usually add the path where the two files sublime.py and sublime_plugin.py are located to some lookup directory. The Jedi package for Sublime Text supports this. Supposedly these stub files should help with that, especially since they have type annotations.

Without taking a closer look, I’m not sure what else you might mean or need.

0 Likes

#3

LSP connects to the python-language-server (pyls) as a backend server. pyls is quite stupid and not able to take some configuration about paths. Therefore it does neigher now about sublime’s internal interpreter libraries nor the sublime.py or sublime_plugin.py. As a result Jedi and the linters used by pyls don’t not know about sublime’s API and mark it as missing/invalid.

As mypy is used by the LSP package to do static code analysis in order to check correct typings, another “issue” is the “missing” typing annotation of the sublime_api. I tried to struggle with mypy but can’t fall in love with it.

0 Likes

#4

Jedi unfortunately doesn’t support the stubs, but I didn’t know that Jedi could be configured with additional paths. Great tip, I’ll have to try this!

0 Likes

#5

I forgot to ask if you had tried the mypy SublimeLinter setup? You for sure had a terrible editing experience with the tools the way they are :slight_smile:

0 Likes

#6

I never dealt with mypy or any other typing analysis tools in python before. I read about typing annotations somewhere and was happy they are optional. I prefer to add a docstring with a description of the arguments and a hint of the data type there. That’s enough I think. The typing annotations produce too much noise in the argument list and make reading a pain.

0 Likes