Skip to content

bad-builtin-groupby (ODOO019)

Preview (since 0.16.2.2) · Related issues · View source

Derived from the odoo linter.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for use of itertools.groupby.

Why is this bad?

itertools.groupby only groups consecutive runs, which is a frequent footgun. Prefer odoo.tools.groupby, which sorts first.

Example

import itertools

itertools.groupby(records, key=lambda r: r.partner_id)

Use instead:

from odoo.tools import groupby

groupby(records, key=lambda r: r.partner_id)