Skip to content

Use a context manager for claiming an interface? #3

@mfreeborn

Description

@mfreeborn

I've just found this library, having been struggling along with a different USB library that wraps libusb, and the modern API and documentation is a real breath of fresh air.

I wonder if claiming/releasing an interface would match nicely with the concept of context managers?

device = usbx.find_device(0x1234)
device.open()

with device.claim_interface(0):  # claim interface 0
    # do stuff with the interface
    pass

# the claim on the interface has no been released
device.close()

This could help ensure that an interface isn't held onto accidentally if an unhandled exception occurs, for example.

I'm not familiar with the innards of the library to know if this would be a trivial/valid interface to adopt.

Some idea could extend to the open/close methods

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions