Skip to content

Commit cc0b9d2

Browse files
authored
sort kwargs in lh.move_resource (#359)
1 parent 5af8c36 commit cc0b9d2

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

pylabrobot/liquid_handling/backends/hamilton/STAR_tests.py

+4
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,10 @@ async def test_move_core(self):
938938
self.plt_car[1],
939939
pickup_distance_from_top=13 - 3.33,
940940
use_arm="core",
941+
# kwargs specific to pickup and drop
942+
channel_1=7,
943+
channel_2=8,
944+
return_core_gripper=True,
941945
)
942946
self._assert_command_sent_once(
943947
"C0ZTid0020xs07975xd0ya1240yb1065pa07pb08tp2350tz2250th2450tt14",

pylabrobot/liquid_handling/liquid_handler.py

+42-9
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,17 @@ def _check_args(
286286
method: Callable,
287287
backend_kwargs: Dict[str, Any],
288288
default: Set[str],
289+
strictness: Strictness,
289290
) -> Set[str]:
290291
"""Checks that the arguments to `method` are valid.
291292
292293
Args:
293294
method: Method to check.
294295
backend_kwargs: Keyword arguments to `method`.
296+
default: Default arguments to `method`. (Of the abstract backend)
297+
strictness: Strictness level. If `Strictness.STRICT`, raises an error if there are extra
298+
arguments. If `Strictness.WARN`, raises a warning. If `Strictness.IGNORE`, logs a debug
299+
message.
295300
296301
Raises:
297302
TypeError: If the arguments are invalid.
@@ -320,8 +325,6 @@ def _check_args(
320325
}
321326
non_default = {arg for arg, param in args.items() if param.default == inspect.Parameter.empty}
322327

323-
strictness = get_strictness()
324-
325328
backend_kws = set(backend_kwargs.keys())
326329

327330
missing = non_default - backend_kws
@@ -441,6 +444,7 @@ async def pick_up_tips(
441444
self.backend.pick_up_tips,
442445
backend_kwargs,
443446
default={"ops", "use_channels"},
447+
strictness=get_strictness(),
444448
)
445449
for extra in extras:
446450
del backend_kwargs[extra]
@@ -572,6 +576,7 @@ async def drop_tips(
572576
self.backend.drop_tips,
573577
backend_kwargs,
574578
default={"ops", "use_channels"},
579+
strictness=get_strictness(),
575580
)
576581
for extra in extras:
577582
del backend_kwargs[extra]
@@ -902,6 +907,7 @@ async def aspirate(
902907
self.backend.aspirate,
903908
backend_kwargs,
904909
default={"ops", "use_channels"},
910+
strictness=get_strictness(),
905911
)
906912
for extra in extras:
907913
del backend_kwargs[extra]
@@ -1097,6 +1103,7 @@ async def dispense(
10971103
self.backend.dispense,
10981104
backend_kwargs,
10991105
default={"ops", "use_channels"},
1106+
strictness=get_strictness(),
11001107
)
11011108
for extra in extras:
11021109
del backend_kwargs[extra]
@@ -1265,7 +1272,9 @@ async def pick_up_tips96(
12651272
if not tip_rack.num_items == 96:
12661273
raise ValueError("Tip rack must have 96 tips")
12671274

1268-
extras = self._check_args(self.backend.pick_up_tips96, backend_kwargs, default={"pickup"})
1275+
extras = self._check_args(
1276+
self.backend.pick_up_tips96, backend_kwargs, default={"pickup"}, strictness=get_strictness()
1277+
)
12691278
for extra in extras:
12701279
del backend_kwargs[extra]
12711280

@@ -1337,7 +1346,9 @@ async def drop_tips96(
13371346
if isinstance(resource, TipRack) and not resource.num_items == 96:
13381347
raise ValueError("Tip rack must have 96 tips")
13391348

1340-
extras = self._check_args(self.backend.drop_tips96, backend_kwargs, default={"drop"})
1349+
extras = self._check_args(
1350+
self.backend.drop_tips96, backend_kwargs, default={"drop"}, strictness=get_strictness()
1351+
)
13411352
for extra in extras:
13421353
del backend_kwargs[extra]
13431354

@@ -1489,7 +1500,9 @@ async def aspirate96(
14891500
):
14901501
raise TypeError(f"Resource must be a Plate, Container, or list of Wells, got {resource}")
14911502

1492-
extras = self._check_args(self.backend.aspirate96, backend_kwargs, default={"aspiration"})
1503+
extras = self._check_args(
1504+
self.backend.aspirate96, backend_kwargs, default={"aspiration"}, strictness=get_strictness()
1505+
)
14931506
for extra in extras:
14941507
del backend_kwargs[extra]
14951508

@@ -1634,7 +1647,9 @@ async def dispense96(
16341647
):
16351648
raise TypeError(f"Resource must be a Plate, Container, or list of Wells, got {resource}")
16361649

1637-
extras = self._check_args(self.backend.dispense96, backend_kwargs, default={"dispense"})
1650+
extras = self._check_args(
1651+
self.backend.dispense96, backend_kwargs, default={"dispense"}, strictness=get_strictness()
1652+
)
16381653
for extra in extras:
16391654
del backend_kwargs[extra]
16401655

@@ -1790,7 +1805,9 @@ async def pick_up_resource(
17901805
direction=direction,
17911806
)
17921807

1793-
extras = self._check_args(self.backend.pick_up_resource, backend_kwargs, default={"pickup"})
1808+
extras = self._check_args(
1809+
self.backend.pick_up_resource, backend_kwargs, default={"pickup"}, strictness=get_strictness()
1810+
)
17941811
for extra in extras:
17951812
del backend_kwargs[extra]
17961813

@@ -2011,22 +2028,38 @@ async def move_resource(
20112028
if put_direction is not None:
20122029
raise NotImplementedError("put_direction is deprecated, use drop_direction instead")
20132030

2031+
extra = self._check_args(
2032+
self.backend.pick_up_resource,
2033+
backend_kwargs,
2034+
default={"pickup"},
2035+
strictness=Strictness.IGNORE,
2036+
)
2037+
pickup_kwargs = {k: v for k, v in backend_kwargs.items() if k not in extra}
2038+
20142039
await self.pick_up_resource(
20152040
resource=resource,
20162041
offset=pickup_offset,
20172042
pickup_distance_from_top=pickup_distance_from_top,
20182043
direction=pickup_direction,
2019-
**backend_kwargs,
2044+
**pickup_kwargs,
20202045
)
20212046

20222047
for intermediate_location in intermediate_locations or []:
20232048
await self.move_picked_up_resource(to=intermediate_location)
20242049

2050+
extra = self._check_args(
2051+
self.backend.drop_resource,
2052+
backend_kwargs,
2053+
default={"drop"},
2054+
strictness=Strictness.IGNORE,
2055+
)
2056+
drop_kwargs = {k: v for k, v in backend_kwargs.items() if k not in extra}
2057+
20252058
await self.drop_resource(
20262059
destination=to,
20272060
offset=destination_offset,
20282061
direction=drop_direction,
2029-
**backend_kwargs,
2062+
**drop_kwargs,
20302063
)
20312064

20322065
async def move_lid(

0 commit comments

Comments
 (0)