vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.21k stars 765 forks source link

pylint and mypy support #862

Open sodul opened 4 years ago

sodul commented 4 years ago

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?

kumahesh commented 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.

[1]https://github.com/vmware/pyvmomi/blob/97d91fe194778e9f6da131d50402e3706708a9e5/pyVmomi/__init__.py#L222

sodul commented 4 years ago

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.

sunaurus commented 4 years ago

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.

zbennett10 commented 4 years ago

I'm going to try and have a crack at this one... :D

intgr commented 3 years ago

@zbennett10 Hi, did you get anywhere with your attempt?

alexshpilkin commented 1 week ago

There seems to have been some initial work in this direction with https://github.com/vmware/pyvmomi/commit/81d0e9fe35478dc1135681147365c295d313b668.