Open sodul opened 4 years ago
Hi @sodul ,
Refer [1], Definitions for vim and vmodl are created by the vmomi runtime on the fly. Static type checking packages won't work. The definition for the name 'vim' loaded from the bindings while run time.
Is it possible to use the if TYPE_CHECKING:
trick to preload the top level names, and possibly all of the names so that the runtime behavior is preserved but type checkers become aware of the types. This would help boost the productivity of the pyvmomi users.
For a complicated library like this, type hints would improve the developer experience IMMENSELY.
It seems that all the type information is already available in documentation, could you not leverage this information in your build process and automatically generate type stubs?
FYI: PEP 561 covers how to distribute type information.
I'm going to try and have a crack at this one... :D
@zbennett10 Hi, did you get anywhere with your attempt?
There seems to have been some initial work in this direction with https://github.com/vmware/pyvmomi/commit/81d0e9fe35478dc1135681147365c295d313b668.
We use pylint and mypy to ensure high quality in our code, unfortunately both tools are confused about the pyvmomi package.
For example
from pyVmomi import vim, vmodl
throws a 'no-name-in-module' error with pylint and we have to silence it.With mypy, and IDEs that support type annotation, we get errors such as
vmodl.query.PropertyCollector? has no attribute "CreateFilter"
.Are there instructions or plans on making pyvmomi work better with pylint and mypy?