Skip to content

Commit 58a2e18

Browse files
authored
get_absolute_location can raise NoLocationError (#338)
2 parents 1f60be4 + 1e4da85 commit 58a2e18

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5858
- get_direction -> pickup_direction
5959
- put_direction -> drop_direction
6060
- `location` parameter of `assign_child_resource` is not optional (https://github.com/PyLabRobot/pylabrobot/pull/336)
61+
- `Resource.get_absolute_location` raises `NoLocationError` instead of `AssertionError` when absolute location is not defined (https://github.com/PyLabRobot/pylabrobot/pull/338)
6162

6263
### Added
6364

Diff for: pylabrobot/resources/errors.py

+6
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ def __init__(self, resource_name: str):
4444
"Please create a PR to complete this resource, or create an issue if you "
4545
"need help. https://github.com/PyLabRobot/pylabrobot"
4646
)
47+
48+
49+
class NoLocationError(Exception):
50+
"""Raised when trying to access a location that does not exist, eg. when calling
51+
get_absolute_location on a resource where some resource between it and the root
52+
has no location."""

Diff for: pylabrobot/resources/resource.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pylabrobot.utils.object_parsing import find_subclass
1212

1313
from .coordinate import Coordinate
14-
from .errors import ResourceNotFoundError
14+
from .errors import NoLocationError, ResourceNotFoundError
1515
from .rotation import Rotation
1616

1717
if sys.version_info >= (3, 11):
@@ -212,7 +212,8 @@ def get_absolute_location(self, x: str = "l", y: str = "f", z: str = "b") -> Coo
212212
z: `"t"`/`"top"`, `"c"`/`"center"`, or `"b"`/`"bottom"`
213213
"""
214214

215-
assert self.location is not None, f"Resource {self.name} has no location."
215+
if self.location is None:
216+
raise NoLocationError(f"Resource {self.name} has no location.")
216217

217218
rotated_anchor = Coordinate(
218219
*matrix_vector_multiply_3x3(

0 commit comments

Comments
 (0)