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

Comparison of values with Unit should not throw ValueError. #149

Closed
mrshannon opened this issue Mar 29, 2019 · 1 comment
Closed

Comparison of values with Unit should not throw ValueError. #149

mrshannon opened this issue Mar 29, 2019 · 1 comment
Assignees
Milestone

Comments

@mrshannon
Copy link
Contributor

mrshannon commented Mar 29, 2019

The __eq__ method of Unit attempts to convert any value it is compared with to a Unit. The problem is when this fails it should return NotImplemented (or raise NotImplementedError) instead of raising ValueError. Because of this, comparisons such as:

Unit('meter') == {}

raises

ValueError: [UT_UNKNOWN] Failed to parse unit "{}": b'Resource temporarily unavailable'

when it should return False. By returning NotImplemented you can punt the decision to the other object or fall back on object identity (if neither object can handle the comparison).

@bjlittle
Copy link
Member

Closed by #150

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

2 participants