bit-count (FURB161)#
Derived from the refurb linter.
Fix is always available.
This rule is unstable and in preview. The --preview
flag is required for use.
What it does#
Checks for uses of bin(...).count("1")
to perform a population count.
Why is this bad?#
In Python 3.10, a bit_count()
method was added to the int
class,
which is more concise and efficient than converting to a binary
representation via bin(...)
.
Example#
Use instead: