This version adds 2 new checks, some bug fixes, and documentation fixes.
Improved Error Messages
Previously Refurb would assume certain identifiers such as Path
where imported as Path
, not pathlib.Path
. This made the context of error messages less helpful since they did not reflect what was actually in the source. Now more checks will use the more accurate pathlib.Path
identifier if needed.
Add use-chain-from-iterable
check (FURB179)
When flattening a list of lists, use the chain.from_iterable
function from the itertools
stdlib package. This function is faster than native list/generator comprehensions or using sum()
with a list default.
Bad:
from itertools import chain
rows = [[1, 2], [3, 4]]
# using list comprehension
flat = [col for row in rows for col in row]
# using sum()
flat = sum(rows, [])
# using chain(*x)
flat = chain(*rows)
Good:
from itertools import chain
rows = [[1, 2], [3, 4]]
flat = chain.from_iterable(rows)
Note:
chain(*x)
may be marginally faster/slower depending on the length ofx
. Since*
might potentially expand to a lot of arguments, it is better to usechain.from_iterable()
when you are unsure.
Add use-abc-shorthand
check (FURB180)
Instead of setting metaclass
directly, inherit from the ABC
wrapper class. This is semantically the same thing, but more succinct.
Bad:
class C(metaclass=ABCMeta):
pass
Good:
class C(ABC):
pass
What's Changed
- Don't emit FURB120 when deleting default arg would change semantics by @dosisod in #289
- Update docs for FURB107 (
use-suppress
) by @dosisod in #292 - Add
use-chain-from-iterable
check by @dosisod in #293 - Tweak versioning docs, bump packages by @dosisod in #294
- Fix failing test in Mypy 1.6.0 by @dosisod in #296
- Bump packages, bump version by @dosisod in #297
Full Changelog: v1.21.0...v1.22.0