From fbbf1573a5547b115c2411ccb6a398eff71d3b33 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Fri, 16 Jun 2023 10:39:47 -0700 Subject: [PATCH] Add explicit deep copy support --- python/lsst/pipe/base/_quantumContext.py | 4 ++++ tests/test_pipelineTask.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/python/lsst/pipe/base/_quantumContext.py b/python/lsst/pipe/base/_quantumContext.py index 09b9a549..01da1204 100644 --- a/python/lsst/pipe/base/_quantumContext.py +++ b/python/lsst/pipe/base/_quantumContext.py @@ -66,6 +66,10 @@ def __post_init__(self) -> None: max_mem = max_mem.to(u.B) object.__setattr__(self, "max_mem", max_mem) + def __deepcopy__(self, memo: Any) -> ExecutionResources: + """Deep copy returns itself because the class is frozen.""" + return self + def _reduce_kwargs(self) -> dict[str, Any]: """Return a dict of the keyword arguments that should be used by `__reduce__`. diff --git a/tests/test_pipelineTask.py b/tests/test_pipelineTask.py index 87ddd285..c0beff0d 100644 --- a/tests/test_pipelineTask.py +++ b/tests/test_pipelineTask.py @@ -22,6 +22,7 @@ """Simple unit test for PipelineTask. """ +import copy import pickle import unittest from typing import Any @@ -337,6 +338,8 @@ def test_ExecutionResources(self): self.assertEqual(res.max_mem.value, 512) self.assertEqual(pickle.loads(pickle.dumps(res)), res) + self.assertIs(res, copy.deepcopy(res)) + with self.assertRaises(u.UnitConversionError): pipeBase.ExecutionResources(max_mem=1 * u.m)