vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.19k stars 766 forks source link

Type stubs: Writable properties are marked as read-only #1017

Closed intgr closed 1 year ago

intgr commented 1 year ago

Describe the bug

In many cases, pyvmomi APIs require writing to properties. For example: https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/add_disk_to_vm.py#L47C30-L57

However, currently all properties are declared with the @property decorator with no setter. This means mypy doesn't allow writing to these properties.

Causes lots of errors like:

add_disk_to_vm.py:50:5: error: Property "fileOperation" defined in "VirtualDeviceSpec" is read-only  [misc]
add_disk_to_vm.py:51:5: error: Property "operation" defined in "VirtualDeviceSpec" is read-only  [misc]
add_disk_to_vm.py:52:5: error: Property "device" defined in "VirtualDeviceSpec" is read-only  [misc]

Reproduction steps

  1. Manually fixed syntax errors reported in #1015
  2. Installed resulting package with pip
  3. Ran mypy over my codebase

Expected behavior

Writable properties should be known to mypy as writable.

Additional context

No response