vmware / vmware/pyvmomi

Incorrect Type Hints on VM Operations

Open
#1,099 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.3k
Forks
763
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

In certain type stubs, the recent changes in 8.0.3.0.0 have resulted in the return type hint of NoReturn being used on certain operations such as VM RebootGuest(). This can be seen here: https://github.com/vmware/pyvmomi/blob/master/pyVmomi/vim/VirtualMachine.pyi#L216

This is problematic because NoReturn does not mean what the author thought it means. The NoReturn type hint means that function cannot return without raising an exception. But RebootGuest() and other functions like it in pyvmomi simply return nothing, which should be represented by a return type hint of -> None instead of -> NoReturn.

This causes erroneous warnings in IDEs about code underneath calls to functions like RebootGuest() being unreachable because the IDE expects that RebootGuest will always throw an exception (since the type hint is NoReturn) or otherwise cannot return.

Can the usage of NoReturn in the auto generated type stubs please be reviewed and updated with the proper hint.

Reproduction steps
  1. Write code to reboot VM using VirtualMachine.RebootGuest() and print "VM reboot initiated" after calling RebootGuest().
  2. Observe errors in IDE indicating that the print statement cannot be reached.

...

Expected behavior

Misleading warnings in IDEs are not present.

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect pyVmomi/vim/VirtualMachine.pyi around line 216 and compare RebootGuest() with the other operations using NoReturn. Trace how the auto-generated type stubs assign these return annotations, then reproduce the IDE warning from the issue and verify that affected operations are represented as returning None.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.