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)
Esempio n. 2
0
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        (next_ty, indicator) = err.next_type_and_indicator()
        error_id = IndicatorStr(next_ty, indicator)

        original = WrappedFunction.find_original(self.fn)
        signature = inspect.signature(original)

        wf = None
        if (hasattr(self.fn, '__wf')):
            wf = getattr(self.fn, '__wf')
        elif isinstance(self.fn, WrappedFunction):
            wf = self.fn

        arglist = []
        for name in signature.parameters:
            if name is self.argument_name:
                arglist.append(IndicatorStr(f"{name}: ") + error_id)
            else:
                if wf is not None:
                    arglist.append(
                        IndicatorStr(
                            f"{name}: {wf.checker_for(name).describe()}"))
                else:
                    arglist.append(IndicatorStr(f"{name}"))

        id = IndicatorStr(f"{original.__name__}(") + IndicatorStr(", ").join(
            arglist)

        if wf is not None:
            id += IndicatorStr(f") -> {wf.checker_for('return').describe()}")
        else:
            id += IndicatorStr(f")")

        if self.declared is None:
            declared = WrappedFunction.find_location(self.fn)
        else:
            declared = self.declared

        if self.stack is not None:
            responsable = Location.from_stack(self.stack)
        else:
            responsable = None

        frame = Frame(id.ty,
                      id.indicator,
                      declared=declared,
                      responsable=responsable)
        return err.with_frame(frame)
Esempio n. 3
0
    def check(self, arg: Any, ctx: ExecutionContext) -> None:
        res = self.callable(arg)
        if not res:
            # raise error on falsy value
            err = UntypyTypeError(given=arg,
                                  expected=self.annotated.describe())
            err = err.with_note(
                f"\n\nNote: Assertion in Callable failed with {repr(res)}.")
            (t, i) = err.next_type_and_indicator()
            err = err.with_frame(
                Frame(t, i, WrappedFunction.find_location(self.callable),
                      None))

            for info in self.annotated.info:
                err = err.with_note("    - " + info)

            raise ctx.wrap(err)
Esempio n. 4
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:
        (next_ty, indicator) = err.next_type_and_indicator()
        return_id = IndicatorStr(next_ty, indicator)

        original = WrappedFunction.find_original(self.fn)

        try:
            signature = inspect.signature(original)  # TODO:!!! FIX BUILTINS
            front_sig = []
            for name in signature.parameters:
                front_sig.append(
                    f"{name}: {self.fn.checker_for(name).describe()}")
            front_sig = f"{format_name(original)}(" + (
                ", ".join(front_sig)) + ") -> "
            return_id = IndicatorStr(front_sig) + return_id
        except:
            return_id = IndicatorStr("???")

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

        if responsable is not None:
            if err.expected is not None and err.given is None:
                # Missing Return-Value?
                err = err.with_note("Did you miss a return statement?")
                last_line = responsable.line_no + responsable.line_span - 1
                responsable = responsable.narrow_in_span(
                    (responsable.file, last_line))
            else:
                responsable = responsable.narrow_in_span(self.reti_loc)

        return err.with_frame(
            Frame(
                return_id.ty,
                return_id.indicator,
                declared=declared,
                responsable=responsable,
            ))
Esempio n. 6
0
    def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
        err = err.with_frame(Frame(self.name, None, None, None))

        if self.upper is not None:
            err = self.upper.wrap(err)
        return err
 def wrap(self, err: UntypyTypeError) -> UntypyTypeError:
     next_type, indicator = err.next_type_and_indicator()
     return err.with_frame(
         Frame(f"list[{next_type}]", (" " * len("list[") + indicator),
               declared=self.declared,
               responsable=Location.from_stack(self.stack)))