Skip to content

Commit

Permalink
Add explicit deep copy support
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jun 21, 2023
1 parent d67b968 commit fbbf157
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/lsst/pipe/base/_quantumContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__`.
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pipelineTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""Simple unit test for PipelineTask.
"""

import copy
import pickle
import unittest
from typing import Any
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit fbbf157

Please sign in to comment.