示例#1
0
    def test_no_annotation_raises(self):
        """ ensure function with no return annotations raises """
        def bob(a):
            pass

        with pytest.raises(NoReturnAnnotation):
            sig_to_args_kwargs(bob)
示例#2
0
    def compatible(self,
                   other: Union["task.Task", "Wrap"],
                   extra_params: Optional[Mapping] = None) -> bool:
        """
        Return True if self (current wrap) provides valid inputs for other.

        Parameters
        ----------
        other
            Another task or wrap
        extra_params
            A mapping of extra parameters
        Returns
        -------
        bool
        """
        if isinstance(other, task.Task):
            other = other.wrap()  # ensure we are working with a wrap
        if not isinstance(other, Wrap):
            return False
        adapter = self.features.get("adapter", None)
        try:
            args, kwargs = sig_to_args_kwargs(self.signature, adapter)
        except NoReturnAnnotation:  # if there is no return annotation
            return True
        sig = other.signature
        check_type = self.check_type and other.check_type
        # check if raw inputs work, if not look in extra_params for args
        if valid_input(sig, *args, check_type=check_type, **kwargs):
            return True
        extra_params = extra_params or other._partials
        # else determine if any params should be provided by extra_params
        return _compatible_extra(sig, args, kwargs, extra_params, check_type)
示例#3
0
 def test_sig_args_kwargs(self, func, adapter, args, kwargs):
     """ ensure the outputs of sig to args kwargs works """
     args_out, kwargs_out = sig_to_args_kwargs(func, adapter=adapter)
     assert args_out == args
     assert kwargs_out == kwargs