pyright.createtypestub
As mentioned earlier, this blog is as much a "note to self" as it is a blog..
Today, I needed typesubs for smbclient of package smbprotocol.
:CocCommand pyright.createstypestub smbclient
This creates the necessary typestubs.
In my case I use nvim with Conquer of Completion and pyright. Yes, I know nvim now has built-in lsp support, but CoC works better for me.
For the stubs to work with pyright you need a pyrightconfig.json file.
It might look something like this
"include": [
"src",
],
"exclude": [
"**/__pycache__"
],
"ignore": [
],
"typeshedPath": "/home/you/yoursource/typeshed",
"stubPath": "/home/you/yoursource/stubs",
"venvPath": ".",
"reportMissingImports": true,
"reportMissingTypeStubs": true,
"pythonVersion": "3.11",
"pythonPlatform": "Linux",
"executionEnvironments": [
{
"root": "/",
"venv": ".venv",
"pythonVersion": "3.11",
"pythonPlatform": "Linux",
"extraPaths": [
""
]
}
]
}
and if /src are your sources it should be present alongside your /src directory.
This should solve missing type hints in smbclient. I did however encounter a different problem (this is not always the case).
To fix this, navigate to your stubs folder /smbclient
and edit the __init__.py file in that directory.
In the __init__.py file add __all__
"""
This type stub file was generated by pyright.
"""
import logging
import smbclient.path
from smbclient._io import SEEK_CUR, SEEK_END, SEEK_SET
from smbclient._os import (
SMBDirEntry,
.
open_file,
readlink,
remove,
.
.
)
# add this after all the imports
__all__ = ["open_file", "readlink", "remove", ....]
and pyright will stop complaining.
There might be a better way of doing this. Please comment if you know of a better way!