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

Implement Device.__eq__() #147

Closed
martijnthe opened this issue May 25, 2016 · 2 comments
Closed

Implement Device.__eq__() #147

martijnthe opened this issue May 25, 2016 · 2 comments

Comments

@martijnthe
Copy link

I'd like to be able to write something like:

devs = set()
devs |= set(usb.core.find(find_all=True, custom_match=matcher_one))
devs |= set(usb.core.find(find_all=True, custom_match=matcher_two))

If matcher_one and matcher_two both match device XYZ, devs will contain two instances of Device referring to XYZ. I'd expect devs to contain only one instance referring to XYZ.

@jonasmalacofilho
Copy link
Member

Thoughts on implementing __eq__ as follows?

def __eq__(self, other):
    return (self.backend, self.bus, self.address) == \
           (other.backend, other.bus, other.address)

Essentially defining equality based on the OS's view of the USB tree, but also taking into account the different possible backends.

Cc: @mcuee

@mcuee
Copy link
Member

mcuee commented Jan 20, 2021

Looks good to me.

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

No branches or pull requests

3 participants