Repository: spotify/luigi
File: luigi/batch_notifier.py (Python)

Code before:

        self._email_format = email().format
        if email().receiver:
            self._default_owner = set(filter(None, email().receiver.split(',')))
        else:
            self._default_owner = set()

    def _update_next_send(self):
        self._next_send = time.time() + 60 * self._config.email_interval

    def _key(self, task_name, family, unbatched_args):
        if self._config.batch_mode == 'all':
            return task_name
        elif self._config.batch_mode == 'family':
            return family
        elif self._config.batch_mode == 'unbatched_params':
            param_str = ', '.join(f'{k}={v}' for k, v in six.iteritems(unbatched_args))
            return f'{family}({param_str})'
        else:
            raise ValueError('Unknown batch mode for batch notifier: {}'.format(
                self._config.batch_mode))

    def _format_expl(self, expl):
        lines = expl.rstrip().split('\n')[-self._config.error_lines:]
        if self._email_format == 'html':
            lines = '\n'.join(lines)
            return f'<pre>{lines}</pre>'
        else:
            return '\n{}'.format('\n'.join(map('      {}'.format, lines)))

    def _expl_body(self, expls):
        lines = [self._format_expl(expl) for expl in expls]
        if lines and self._email_format != 'html':
            lines.append('')
        return '\n'.join(lines)

    def _format_task(self, task_tuple):
        task, failure_count, disable_count, scheduling_count = task_tuple
        counts = [
            _plural_format('{} failure{}', failure_count),
            _plural_format('{} disable{}', disable_count),
            _plural_format('{} scheduling failure{}', scheduling_count),
        ]
        count_str = ', '.join(filter(None, counts))
        return f'{task} ({count_str})'

    def _format_tasks(self, tasks):
        lines = map(self._format_task, sorted(tasks, key=self._expl_key))
        if self._email_format == 'html':
            lines_joined = '\n<br>'.join(lines)
            return f'<li>{lines_joined}'

Review comment (suggestion):
Please avoid reassigning to `lines`. They are not even the same type. I guess you forgot to change it to `lines_joined`.

Code after:

        self._email_format = email().format
        if email().receiver:
            self._default_owner = set(filter(None, email().receiver.split(',')))
        else:
            self._default_owner = set()

    def _update_next_send(self):
        self._next_send = time.time() + 60 * self._config.email_interval

    def _key(self, task_name, family, unbatched_args):
        if self._config.batch_mode == 'all':
            return task_name
        elif self._config.batch_mode == 'family':
            return family
        elif self._config.batch_mode == 'unbatched_params':
            param_str = ', '.join('{}={}'.format(k, v) for k, v in unbatched_args.items())
            return '{}({})'.format(family, param_str)
        else:
            raise ValueError('Unknown batch mode for batch notifier: {}'.format(
                self._config.batch_mode))

    def _format_expl(self, expl):
        lines = expl.rstrip().split('\n')[-self._config.error_lines:]
        if self._email_format == 'html':
            return '<pre>{}</pre>'.format('\n'.join(lines))
        else:
            return '\n{}'.format('\n'.join(map('      {}'.format, lines)))

    def _expl_body(self, expls):
        lines = [self._format_expl(expl) for expl in expls]
        if lines and self._email_format != 'html':
            lines.append('')
        return '\n'.join(lines)

    def _format_task(self, task_tuple):
        task, failure_count, disable_count, scheduling_count = task_tuple
        counts = [
            _plural_format('{} failure{}', failure_count),
            _plural_format('{} disable{}', disable_count),
            _plural_format('{} scheduling failure{}', scheduling_count),
        ]
        count_str = ', '.join(filter(None, counts))
        return '{} ({})'.format(task, count_str)

    def _format_tasks(self, tasks):
        lines = map(self._format_task, sorted(tasks, key=self._expl_key))
        if self._email_format == 'html':
            return '<li>{}'.format('\n<br>'.join(lines))
        else:
            return '- {}'.format('\n  '.join(lines))