Coverage for python/lsst/daf/relation/_transfer.py: 56%
28 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 09:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-16 09:55 +0000
1# This file is part of daf_relation.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22from __future__ import annotations
24__all__ = ("Transfer",)
26import dataclasses
27from typing import TYPE_CHECKING, final
29from ._engine import Engine
30from ._marker_relation import MarkerRelation
32if TYPE_CHECKING:
33 from ._relation import Relation
36@final
37@dataclasses.dataclass(frozen=True, kw_only=True)
38class Transfer(MarkerRelation):
39 """A `MarkerRelation` operation that represents moving relation content
40 from one engine to another.
42 A single `Engine` cannot generally process a relation tree that contains
43 transfers. The `Processor` class provides a framework for handling these
44 trees.
45 """
47 destination: Engine
48 """Engine the target relation content will be transferred to (`Engine`).
49 """
51 @property
52 def engine(self) -> Engine:
53 # Docstring inherited.
54 return self.destination
56 def __str__(self) -> str:
57 return f"→[{self.destination}]({self.target})"
59 @classmethod
60 def simplify(cls, target: Relation, destination: Engine) -> Relation | None:
61 if target.is_locked:
62 return None
63 match target:
64 case Transfer(target=new_target):
65 if destination == new_target.engine:
66 return new_target
67 else:
68 return cls.simplify(new_target, destination)
69 case MarkerRelation(target=new_target):
70 return cls.simplify(new_target, destination)
71 return None