Errors #5
Replies: 2 comments 5 replies
-
My current library just makes it a nan or error unit since it originates in C++ and used in some contexts where exceptions are not used. There Unit is undefined or couldn't be constructed for some reason |
Beta Was this translation helpful? Give feedback.
-
I like this on paper: it'd be nice to allow user code to catch unit-related exceptions in a generic fashion, e.g. from unit_api.exceptions import UndefinedUnitError
try:
...
except UndefinedUnitError:
... Unfortunately the only way I know how to implement this would be to make For reference, I naively attempted to avoid inheritance using from typing import Protocol, runtime_checkable
@runtime_checkable
class UnitConversionError(Exception, Protocol):
from_unit: str
to_unit: str unfortunately this doesn't work:
It's also not possible to avoid this broken multiple inheritance scheme: trying to drop
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
These are pint's errors that I'd expect could be common accross packages
Beta Was this translation helpful? Give feedback.
All reactions