예제 #1
0
 def __init__(self, function):
     if self._type_params is None:
         raise TypeError(
             "Cannot instantiate a generic Function; the parameter and return types must be specified"
         )
     if isinstance(function, str):
         self.graft = client.keyref_graft(function)
         self.params = ()
     elif isinstance(function, Function):
         # If the `function` is compatible with our types (remember, `isinstance` has fancy logic to
         # check this for us) use its graft, otherwise error.
         if isinstance(function, type(self)):
             self.graft = function.graft
             self.params = function.params
         else:
             raise TypeError(f"Expected a {type(self).__name__}. "
                             f"Got a {type(function).__name__}.\n"
                             "Their signatures are incompatible:\n"
                             f"need: {self.__signature__}\n"
                             f"got:  {function.__signature__}")
     elif callable(function):
         result = self._delay(function, self.return_type, *self.arg_types,
                              **self.kwarg_types)
         self.graft = result.graft
         self.params = result.params
     else:
         raise ProxyTypeError(
             "Function must be a Python callable or string name, "
             "not {}".format(function))
예제 #2
0
    def __init__(self, name, default, label=""):
        self.graft = client.keyref_graft(name)
        self.params = (self,)
        self._name = name

        self._default = default
        self._label = label
예제 #3
0
def identifier(name, type_):
    """
    Create a Proxytype instance that references a graft key.
    Internal method meant for references to builtin constants or parameters.
    You shouldn't use this directly; consider `parameter` instead.
    """
    return type_._from_graft(graft_client.keyref_graft(name))
예제 #4
0
 def _as_param(cls, name: str):
     "Construct a new instance of `cls` as a parameter referencing `name`."
     new = cls._from_graft(client.keyref_graft(name))
     new.params = (new, )
     # ^ NOTE: this is all that makes something a parameter: its params list contains itself.
     # that way, all other objects that interact with it will propagate that parameter forward.
     new._name = name
     return new
예제 #5
0
 def __init__(self):
     self.graft = client.keyref_graft("Ellipsis")
예제 #6
0
 def test_init_str(self):
     func = Function[{}, Int]("foo")
     assert func.graft == client.keyref_graft("foo")
     assert func.params == ()
예제 #7
0
 def __init__(self):
     self.graft = client.keyref_graft("wf.Ellipsis")
     self.params = ()
예제 #8
0
def identifier(name, type_):
    """
    Create a Proxytype instance that references a graft key; i.e. for references to builtin constants or parameters.
    """
    return type_._from_graft(graft_client.keyref_graft(name))