Opened 2 years ago
Closed 2 years ago
#34676 closed Cleanup/optimization (fixed)
Normalise MeasureBase unit not found exceptions to use AttributeError
| Reported by: | Andrew Northall | Owned by: | Andrew Northall |
|---|---|---|---|
| Component: | GIS | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Andrew Northall | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I am making use of the Distance class in contrib.gis.measure in my project and it is annoying to have to constantly catch Exception when checking if a particular unit exists. It would be better to have a specific exception for this case.
Change History (9)
comment:1 by , 2 years ago
| Cc: | added |
|---|---|
| Description: | modified (diff) |
| Owner: | changed from to |
follow-up: 3 comment:2 by , 2 years ago
follow-up: 4 comment:3 by , 2 years ago
Replying to Mariusz Felisiak:
I don't think that separate exception class is justified, I'd change to the
ValueError.
Thanks - if you'd rather not have a class, would it perhaps be better to normalise all unit not found exceptions to AttributeError?
default_units() already returns AttributeError if the units are not found (before I changed it in my PR), so would it be better just to make unit_attname() also return AttributeError to match (and hence retain backwards compatibility with people who may depend on default_units() returning AttributeError)?
Or would you leave default_units() as AttributeError and have unit_attname() return ValueError?
follow-up: 6 comment:4 by , 2 years ago
Replying to Andrew Northall:
Replying to Mariusz Felisiak:
I don't think that separate exception class is justified, I'd change to the
ValueError.
Thanks - if you'd rather not have a class, would it perhaps be better to normalise all unit not found exceptions to
AttributeError?
default_units()already returnsAttributeErrorif the units are not found (before I changed it in my PR), so would it be better just to makeunit_attname()also returnAttributeErrorto match (and hence retain backwards compatibility with people who may depend ondefault_units()returningAttributeError)?
Or would you leave
default_units()asAttributeErrorand haveunit_attname()returnValueError?
We should unify both exceptions. I'd use AttributeError as it will be backward compatible.
comment:5 by , 2 years ago
| Summary: | Add DistanceUnitDoesNotExist exception to contrib.gis.measure → Normalise MeasureBase unit not found exceptions to use AttributeError |
|---|
comment:7 by , 2 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:8 by , 2 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
I don't think that separate exception class is justified, I'd change to the
ValueError.