예제 #1
0
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        (original_expected, _ind) = err.next_type_and_indicator()
        err = ArgumentExecutionContext(self.wf, None, self.arg_name).wrap(err)

        responsable = WrappedFunction.find_location(self.wf)

        (decl, ind) = err.next_type_and_indicator()
        err = err.with_frame(
            Frame(decl,
                  ind,
                  declared=self.wf.declared(),
                  responsable=responsable))

        err = err.with_note(
            f"The argument '{self.arg_name}' of method '{WrappedFunction.find_original(self.wf).__name__}' violates the {self.wf.protocol.protocol_type()} '{self.wf.protocol.proto.__name__}'."
        )
        err = err.with_note(
            f"The annotation '{original_expected}' is incompatible with the {self.wf.protocol.protocol_type()}'s annotation '{self.wf.checker_for(self.arg_name).describe()}'\nwhen checking against the following value:"
        )

        previous_chain = UntypyTypeError(
            self.me, f"{self.wf.protocol.protoname()}"
        ).with_note(
            f"Type '{type(self.me).__name__}' does not implement {self.wf.protocol.protocol_type()} '{self.wf.protocol.protoname()}' correctly."
        )

        previous_chain = self.ctx.wrap(previous_chain)
        # err = err.with_inverted_responsibility_type()

        return err.with_previous_chain(previous_chain)
예제 #2
0
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        (original_expected, _ind) = err.next_type_and_indicator()
        err = ArgumentExecutionContext(self.wf, None, self.arg_name).wrap(err)

        responsable = WrappedFunction.find_location(self.wf)

        (decl, ind) = err.next_type_and_indicator()
        err = err.with_frame(
            Frame(decl,
                  ind,
                  declared=self.wf.declared(),
                  responsable=responsable))

        err = err.with_note(
            f"Argument {self.arg_name} of method {WrappedFunction.find_original(self.wf).__name__} violates the type declared by the {self.wf.protocol.protocol_type()} {self.wf.protocol.proto.__name__}."
        )
        err = err.with_note(
            f"Annotation {original_expected} is incompatible with the {self.wf.protocol.protocol_type()}'s annotation {self.wf.checker_for(self.arg_name).describe()}."
        )

        previous_chain = UntypyTypeError(
            self.me, f"{self.wf.protocol.protoname()}"
        ).with_header(
            f"{type(self.me).__name__} does not implement {self.wf.protocol.protocol_type()} {self.wf.protocol.protoname()} correctly."
        )

        previous_chain = self.ctx.wrap(previous_chain)
        # err = err.with_inverted_responsibility_type()

        return err.with_previous_chain(previous_chain)
예제 #3
0
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        (original_expected, _ind) = err.next_type_and_indicator()
        err = ArgumentExecutionContext(self.tc.inner, None,
                                       self.arg_name).wrap(err)

        func_decl = WrappedFunction.find_location(self.tc.inner)

        name = WrappedFunction.find_original(self.tc.inner).__name__

        (decl, ind) = err.next_type_and_indicator()
        err = err.with_frame(
            Frame(decl, ind, declared=None, responsable=func_decl))

        previous_chain = UntypyTypeError(
            f"def {name}{self.tc.inner.describe()}", f"{self.tc.describe()}")
        (decl, ind) = previous_chain.next_type_and_indicator()
        previous_chain = previous_chain.with_frame(
            Frame(decl, ind, declared=func_decl, responsable=None))

        err = err.with_note(
            f"The argument '{self.arg_name}' of method '{name}' violates the signature of {self.tc.describe()}."
        )

        previous_chain = self.upper.wrap(previous_chain)

        return err.with_previous_chain(previous_chain)
 def wrapper(*args, **kwargs):
     # first is this fn
     caller = sys._getframe(1)
     (args, kwargs, bindings) = self.wrap_arguments(lambda n: ArgumentExecutionContext(self, caller, n), args,
                                                    kwargs)
     ret = self.inner(*args, **kwargs)
     ret = self.wrap_return(ret, bindings, ReturnExecutionContext(self))
     return ret
예제 #5
0
 def wrapper_cls(*args, **kwargs):
     caller = sys._getframe(1)
     (args, kwargs, bindings) = self.wrap_arguments(
         lambda n: ArgumentExecutionContext(
             self, caller, n, declared=self.declared()), args, kwargs)
     ret = fn(*args, **kwargs)
     return self.wrap_return(ret, bindings,
                             ReturnExecutionContext(self))
예제 #6
0
 def wrapper_self(me, *args, **kwargs):
     if name == '__init__':
         me.__return_ctx = None
         me.__inner = self.create_fn()
     caller = sys._getframe(1)
     (args, kwargs, bindings) = self.wrap_arguments(
         lambda n: ArgumentExecutionContext(
             wrapper_self, caller, n, declared=self.declared()),
         (me.__inner, *args), kwargs)
     ret = fn(*args, **kwargs)
     if me.__return_ctx is None:
         return self.wrap_return(ret, bindings,
                                 ReturnExecutionContext(self))
     else:
         return self.wrap_return(ret, bindings, me.__return_ctx)
예제 #7
0
        def wrapper(me, *args, **kwargs):
            inner_object = me.__inner
            inner_ctx = me.__ctx

            caller = sys._getframe(1)
            (args, kwargs, bind1) = self.wrap_arguments(
                lambda n: ArgumentExecutionContext(fn_of_protocol, caller, n),
                (inner_object, *args), kwargs)
            if isinstance(self.inner, WrappedFunction):
                (args, kwargs, bind2) = self.inner.wrap_arguments(
                    lambda n: ProtocolArgumentExecutionContext(
                        self, n, inner_object, inner_ctx), args, kwargs)
            ret = fn(*args, **kwargs)
            if isinstance(self.inner, WrappedFunction):
                ret = self.inner.wrap_return(
                    ret, bind2,
                    ProtocolReturnExecutionContext(self, ResponsibilityType.IN,
                                                   inner_object, inner_ctx))
            return self.wrap_return(
                ret, bind1,
                ProtocolReturnExecutionContext(self, ResponsibilityType.OUT,
                                               inner_object, inner_ctx))