Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Type Hints on VM Operations #1099

Open
EnigmaticCypher opened this issue Feb 11, 2025 · 3 comments
Open

Incorrect Type Hints on VM Operations #1099

EnigmaticCypher opened this issue Feb 11, 2025 · 3 comments
Labels

Comments

@EnigmaticCypher
Copy link

EnigmaticCypher commented Feb 11, 2025

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

@EnigmaticCypher
Copy link
Author

EnigmaticCypher commented Feb 11, 2025

Noting that the usage of the NoReturn type hint may not only be an issue in the VirtualMachine class, I imagine it's also present in a bunch of other classes, and is likely the result of a logic fault in the automatic code generator that outputs those type stubs based on the SOAP schemas.

@EnigmaticCypher
Copy link
Author

Here's a rather succinct stack overflow answer that explains the type: https://stackoverflow.com/questions/48038149/noreturn-vs-none-in-void-functions-type-annotations-in-python-3-6

@EnigmaticCypher
Copy link
Author

EnigmaticCypher commented Feb 11, 2025

Marking as related to #1080 because another user has in that ticket mentioned the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant