vmware / pyvmomi

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

Type stubs: Exception types must inherit from (Base)Exception #1020

Closed intgr closed 1 year ago

intgr commented 1 year ago

Describe the bug

There are type stubs for some exception calsses, such as vmodl.MethodFault. These should derive from Python's Exception or BaseException classes.

Without that, using the class in an except clause causes mypy errors. For example https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/waitforupdates.py#LL109C36-L109C36

    try:
        pc_filter = prop_collector.CreateFilter(filter_spec, True)
        atexit.register(pc_filter.Destroy)
        return pc_filter
    except vmodl.MethodFault as ex:
        #  ^^^^^^^^^^^^^^^^^

Mypy complains:

waitforupdates.py:227:12: error: Exception type must be derived from BaseException  [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

Handling exceptions should not cause typechecker errors.

Additional context

No response