示例#1
0
def mirror():
    """Fixture for forming basic mirrored function"""
    def run_func(*args):
        return sum(args)

    def match_func(a, b):
        """Sums two values"""
        return 0

    return mirror_func(match_func, run_func)
示例#2
0
    def __init_subclass__(cls, mirror_set_positions=True, **kwargs):
        """
        Automates function mirroring when subclasses are created.

        When this class is subclassed, set the subclass's ``__init__`` method
        to mirror its ``set_positions`` method (since all ``__init__``
        arguments are passed to ``set_positions`` anyway).

        Parameters
        ----------
        mirror_set_positions : boolean, optional
            Whether or not to mirror the set_positions method.

        Warnings
        --------
        If `mirror_set_positions` is ``True``, the ``__init__`` method of the
        class is replaced by ``super().__init__``.

        """
        super().__init_subclass__(**kwargs)
        if mirror_set_positions:
            cls.__init__ = mirror_func(cls.set_positions, Detector.__init__)
示例#3
0
    def _mirror_build_function(self):
        """
        Mirror the build function of the subsets.

        For a detector comprised of subsets which hasn't overwritten the
        default ``build_antennas`` method, mirrors the function signature of
        ``build_antennas`` from the base subset (as long as the signature is
        the same for all subsets).

        """
        if hasattr(self, '_actual_build'):
            self.build_antennas = self._actual_build
        if (not self._is_base_subset
                and self.build_antennas.__func__ == Detector.build_antennas
                and self._subset_builds_match):
            self._actual_build = self.build_antennas
            for sub in self.subsets:
                if hasattr(sub, 'build_antennas'):
                    break
            self.build_antennas = mirror_func(sub.build_antennas,
                                              Detector.build_antennas,
                                              self=self)
        else:
            self._actual_build = self.build_antennas