Пример #1
0
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        err = ReturnExecutionContext(self.wf).wrap(err)

        if err.responsibility_type is self.invert:
            return err

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

        inner = self.wf.inner
        if isinstance(inner, WrappedFunction):
            err = err.with_note(
                f"The return value of method '{WrappedFunction.find_original(self.wf).__name__}' does violate the {self.wf.protocol.protocol_type()} '{self.wf.protocol.proto.__name__}'."
            )
            err = err.with_note(
                f"The annotation '{inner.checker_for('return').describe()}' is incompatible with the {self.wf.protocol.protocol_type()}'s annotation '{self.wf.checker_for('return').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)
        return err.with_previous_chain(previous_chain)
Пример #2
0
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        (type_declared, indicator_line) = self.declared_and_indicator(err)

        declared = WrappedFunction.find_location(self.fn.inner)

        responsable = Location.from_stack(self.stack)

        frame = Frame(
            type_declared,
            indicator_line,
            declared=declared,
            responsable=responsable,
        )

        err = err.with_frame(frame)
        err = err.with_inverted_responsibility_type()
        return self.upper.wrap(err)
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        desc = lambda s: s.describe()
        front_str = f"Callable[[{', '.join(map(desc, self.fn.argument_checker))}], "
        responsable = WrappedFunction.find_location(self.fn.inner)

        if self.invert:
            (next_ty, indicator) = err.next_type_and_indicator()
            err = ReturnExecutionContext(self.fn.inner).wrap(err)
            err = err.with_frame(
                Frame(f"{front_str}{next_ty}]",
                      (" " * len(front_str)) + indicator,
                      declared=None,
                      responsable=responsable))
            err = err.with_inverted_responsibility_type()
            return self.upper.wrap(err)

        (next_ty, indicator) = err.next_type_and_indicator()
        err = err.with_frame(
            Frame(f"{front_str}{next_ty}]", (" " * len(front_str)) + indicator,
                  declared=None,
                  responsable=responsable))

        return self.upper.wrap(err)