Skip to content

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

Closed
@mrshannon

Description

@mrshannon

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).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions