Exemple #1
0
    def format_return(self, event):
        # If a call ends due to an exception, we still get a 'return' event
        # with arg = None. This seems to be the only way to tell the difference
        # https://stackoverflow.com/a/12800909/2482744
        opname = event.opname
        arg = event.arg
        if arg is None:
            if opname == 'END_FINALLY':
                if event.frame_info.had_exception:
                    return [
                        u'{c.red}??? Call either returned None or ended by exception{c.reset}'
                        .format(c=self.c)
                    ]
            elif opname not in ('RETURN_VALUE', 'YIELD_VALUE'):
                return [
                    u'{c.red}!!! Call ended by exception{c.reset}'.format(
                        c=self.c)
                ]

        value = self.highlighted(my_cheap_repr(arg))
        if event.comprehension_type:
            prefix = plain_prefix = u'Result: '
        else:
            plain_prefix = u'<<< {description} value from {func}: '.format(
                description='Yield' if opname == 'YIELD_VALUE' else 'Return',
                func=event.code_qualname(),
            )
            prefix = u'{c.green}{}{c.reset}'.format(
                plain_prefix,
                c=self.c,
            )
        return indented_lines(prefix, value, plain_prefix=plain_prefix)
Exemple #2
0
    def update_variables(self, watch, watch_extras, event, whitelist):
        self.last_line_no = self.frame.f_lineno
        old_local_reprs = self.local_reprs
        self.local_reprs = OrderedDict(
            (source, my_cheap_repr(value))
            for source, value in self.get_local_reprs(watch, watch_extras,
                                                      whitelist))

        if self.comprehension_type:
            for name, value_repr in self.local_reprs.items():
                values = self.comprehension_variables.setdefault(name, [])
                if not values or values[-1] != value_repr:
                    values.append(value_repr)
                    values[:] = truncate_list(values, 11)
            if event in ('return', 'exception'):
                return [
                    (name, ', '.join(values))
                    for name, values in self.comprehension_variables.items()
                ]
            else:
                return []

        variables = []
        for name, value_repr in self.local_reprs.items():
            if name not in old_local_reprs or old_local_reprs[
                    name] != value_repr:
                variables.append((name, value_repr))
        return variables
Exemple #3
0
 def _format_key(self, key):
     return '[{}]'.format(
         my_cheap_repr(key).replace('\n', ' ').replace('\r', ' '))