github dosisod/refurb v1.8.0
Version 1.8.0

latest releases: v2.0.0, v1.28.0, v1.27.0...
21 months ago

This release includes some bug fixes, new checks, as well as the ability to enable/disable checks based on category!

Categories

Checks can now have a categories field where they specify what categories they fit into. On the command line, you can use --enable "#category" to enable all checks in that category. The same applies for ignore and disable. This feature is also available in config files. See the docs for more info.

Add "simplify comprehension" Check (FURB137)

This check recommends that you simplify your usage of comprehensions by:

  • Removing nested layers of comprehensions (ie, list([...])
  • Write list/set comprehensions using shorthand notation

Here are the examples from the explainer:

nums = [1, 1, 2, 3]

nums_times_10 = list(num * 10 for num in nums)
unique_squares = set(num ** 2 for num in nums)
number_tuple = tuple([num ** 2 for num in nums])

And the suggested improvements:

nums = [1, 1, 2, 3]

nums_times_10 = [num * 10 for num in nums]
unique_squares = {num ** 2 for num in nums}
number_tuple = tuple(num ** 2 for num in nums)

Add "use comprehensions" check (FURB138)

This check will find instances where you append a bunch of elements to a new list, and suggest that you use a list comprehension instead. This can result in higher performance, and in some cases can greatly improve readability.

Example from the explainer:

nums = [1, 2, 3, 4]
odds = []

for num in nums:
    if num % 2:
        odds.append(num)

Suggested improvement:

nums = [1, 2, 3, 4]
odds = [num for num in nums if num % 2]

Add "no multi-line lstrip()" Check (FURB139)

This check will find multi-line strings that can be written without the use of the lstrip() function:

"""
Some docstring
""".lstrip()

Suggested improvement:

"""\
Some docstring
"""

What's Changed

  • Add ability to enable/disable errors based on category by @dosisod in #123
  • Update error messages for FURB108 and FURB124: by @dosisod in #124
  • Add enhancement template by @dosisod in #125
  • Add "simplify comprehension" check by @dosisod in #126
  • Add "use comprehensions" check by @dosisod in #127
  • Bump packages by @dosisod in #128
  • Fix set comprehensions being suggested to be removed for list/tuple constructions by @dosisod in #131
  • Add ability to detect comparison to empty list/dict in FURB115 by @dosisod in #132
  • Add more nodes to the is_equivalent function by @dosisod in #134
  • Add "no multiline lstrip" check by @dosisod in #135
  • Bump packages and version by @dosisod in #136

Full Changelog: v1.7.0...v1.8.0

Don't miss a new refurb release

NewReleases is sending notifications on new releases.