From 294381407df6723b5411be05d5737166b5b5a381 Mon Sep 17 00:00:00 2001 From: Camillo Moschner Date: Fri, 27 Mar 2026 10:36:29 +0000 Subject: [PATCH 1/5] create `scale.read_weight()`, deprecate `scale.get_weight()` --- pylabrobot/scales/scale.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pylabrobot/scales/scale.py b/pylabrobot/scales/scale.py index 5ce786d42ff..f2e0d12fac1 100644 --- a/pylabrobot/scales/scale.py +++ b/pylabrobot/scales/scale.py @@ -1,4 +1,5 @@ from typing import Optional +import warnings from pylabrobot.machines.machine import Machine from pylabrobot.resources import Resource, Rotation @@ -42,4 +43,14 @@ async def zero(self, **backend_kwargs): async def get_weight(self, **backend_kwargs) -> float: """Get the weight in grams""" + warnings.warn( + "Scale frontend `scale.get_weight is deprecated and will be removed in 2026-06" + "use `scale.read_weight instead", + DeprecationWarning, + stacklevel=2, + ) return await self.backend.get_weight(**backend_kwargs) + + async def read_weight(self, **backend_kwargs) -> float: + """Get the weight in grams""" + return await self.backend.read_weight(**backend_kwargs) From cf1fea526b9ef9fe9519bc7e7cad7272f7b4c01d Mon Sep 17 00:00:00 2001 From: Camillo Moschner Date: Fri, 27 Mar 2026 11:26:30 +0000 Subject: [PATCH 2/5] Improve scale frontend: correct deprecation warning and add docstrings --- pylabrobot/scales/scale.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/pylabrobot/scales/scale.py b/pylabrobot/scales/scale.py index f2e0d12fac1..0c7bc11990a 100644 --- a/pylabrobot/scales/scale.py +++ b/pylabrobot/scales/scale.py @@ -34,23 +34,40 @@ def __init__( self.backend: ScaleBackend = backend # fix type async def tare(self, **backend_kwargs): - """Tare the scale""" + """Reset the displayed weight to zero, storing the current + weight as the tare value. + + Use this to measure only the weight of material added after + taring (e.g. ignoring a container). + Note: taring does not restore scale capacity. + """ await self.backend.tare(**backend_kwargs) async def zero(self, **backend_kwargs): - """Zero the scale""" + """Calibrate the scale's zero point to the current load. + + Establishes the baseline "empty" reading. Unlike tare, this + does not account for container weight — it simply resets what + the scale considers zero. Does not restore scale capacity. + """ await self.backend.zero(**backend_kwargs) async def get_weight(self, **backend_kwargs) -> float: - """Get the weight in grams""" + """Deprecated: use :meth:`read_weight` instead.""" warnings.warn( - "Scale frontend `scale.get_weight is deprecated and will be removed in 2026-06" - "use `scale.read_weight instead", + "scale.get_weight() is deprecated and will be removed in 2026-06. " + "Use scale.read_weight() instead.", DeprecationWarning, stacklevel=2, ) - return await self.backend.get_weight(**backend_kwargs) + return await self.backend.read_weight(**backend_kwargs) async def read_weight(self, **backend_kwargs) -> float: - """Get the weight in grams""" + """Read the current weight in grams. + + The scale may take a moment to stabilize after loading. + Use the ``timeout`` backend kwarg to control stability + behavior: ``"stable"`` waits for a settled reading, ``0`` returns + immediately, or pass a number of seconds to wait at most that long. + """ return await self.backend.read_weight(**backend_kwargs) From bf064260a587ec88b7767ff350c5293b8e2e016a Mon Sep 17 00:00:00 2001 From: Camillo Moschner Date: Fri, 27 Mar 2026 11:28:29 +0000 Subject: [PATCH 3/5] `make format` --- pylabrobot/scales/scale.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pylabrobot/scales/scale.py b/pylabrobot/scales/scale.py index 0c7bc11990a..c942c3291e3 100644 --- a/pylabrobot/scales/scale.py +++ b/pylabrobot/scales/scale.py @@ -1,5 +1,5 @@ -from typing import Optional import warnings +from typing import Optional from pylabrobot.machines.machine import Machine from pylabrobot.resources import Resource, Rotation @@ -55,18 +55,18 @@ async def zero(self, **backend_kwargs): async def get_weight(self, **backend_kwargs) -> float: """Deprecated: use :meth:`read_weight` instead.""" warnings.warn( - "scale.get_weight() is deprecated and will be removed in 2026-06. " - "Use scale.read_weight() instead.", - DeprecationWarning, - stacklevel=2, - ) + "scale.get_weight() is deprecated and will be removed in 2026-06. " + "Use scale.read_weight() instead.", + DeprecationWarning, + stacklevel=2, + ) return await self.backend.read_weight(**backend_kwargs) async def read_weight(self, **backend_kwargs) -> float: """Read the current weight in grams. The scale may take a moment to stabilize after loading. - Use the ``timeout`` backend kwarg to control stability + Use the ``timeout`` backend kwarg to control stability behavior: ``"stable"`` waits for a settled reading, ``0`` returns immediately, or pass a number of seconds to wait at most that long. """ From 79492278b8539c4d85e621c7e51a4ecb7327605e Mon Sep 17 00:00:00 2001 From: Camillo Moschner Date: Fri, 27 Mar 2026 11:37:24 +0000 Subject: [PATCH 4/5] reorganise scale frontend method order based on usage order --- pylabrobot/scales/scale.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pylabrobot/scales/scale.py b/pylabrobot/scales/scale.py index c942c3291e3..8f0a5b01ad4 100644 --- a/pylabrobot/scales/scale.py +++ b/pylabrobot/scales/scale.py @@ -33,25 +33,25 @@ def __init__( ) self.backend: ScaleBackend = backend # fix type - async def tare(self, **backend_kwargs): - """Reset the displayed weight to zero, storing the current - weight as the tare value. - - Use this to measure only the weight of material added after - taring (e.g. ignoring a container). - Note: taring does not restore scale capacity. - """ - await self.backend.tare(**backend_kwargs) - - async def zero(self, **backend_kwargs): + async def zero(self, **backend_kwargs) -> None: """Calibrate the scale's zero point to the current load. Establishes the baseline "empty" reading. Unlike tare, this - does not account for container weight — it simply resets what + does not account for container weight - it simply resets what the scale considers zero. Does not restore scale capacity. """ await self.backend.zero(**backend_kwargs) + async def tare(self, **backend_kwargs) -> None: + """Reset the displayed weight to zero, storing the current + weight as the tare value. + + Use this to measure only the weight of material added after + taring (e.g. ignoring a container). + Note: taring does not restore scale capacity. + """ + await self.backend.tare(**backend_kwargs) + async def get_weight(self, **backend_kwargs) -> float: """Deprecated: use :meth:`read_weight` instead.""" warnings.warn( From 7c0dba003d167d3bb8644eadfb6d2e1a8418a864 Mon Sep 17 00:00:00 2001 From: Camillo Moschner Date: Fri, 27 Mar 2026 11:48:00 +0000 Subject: [PATCH 5/5] move deprecated to its own section --- pylabrobot/scales/scale.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pylabrobot/scales/scale.py b/pylabrobot/scales/scale.py index 8f0a5b01ad4..5fbbc1e4a37 100644 --- a/pylabrobot/scales/scale.py +++ b/pylabrobot/scales/scale.py @@ -1,3 +1,5 @@ +"""Frontend for analytical scales (zero, tare, read weight).""" + import warnings from typing import Optional @@ -52,16 +54,6 @@ async def tare(self, **backend_kwargs) -> None: """ await self.backend.tare(**backend_kwargs) - async def get_weight(self, **backend_kwargs) -> float: - """Deprecated: use :meth:`read_weight` instead.""" - warnings.warn( - "scale.get_weight() is deprecated and will be removed in 2026-06. " - "Use scale.read_weight() instead.", - DeprecationWarning, - stacklevel=2, - ) - return await self.backend.read_weight(**backend_kwargs) - async def read_weight(self, **backend_kwargs) -> float: """Read the current weight in grams. @@ -71,3 +63,16 @@ async def read_weight(self, **backend_kwargs) -> float: immediately, or pass a number of seconds to wait at most that long. """ return await self.backend.read_weight(**backend_kwargs) + + # # # Deprecated # # # + # TODO: remove after 2026-06 + + async def get_weight(self, **backend_kwargs) -> float: + """Deprecated: use :meth:`read_weight` instead.""" + warnings.warn( + "scale.get_weight() is deprecated and will be removed in 2026-06. " + "Use scale.read_weight() instead.", + DeprecationWarning, + stacklevel=2, + ) + return await self.backend.read_weight(**backend_kwargs)