Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We can remove the ignore of some rules that can be autofixed or that we don't break anyways.
Changes
Remove ignore for these rules
Details
assert-false (B011)
Derived from the flake8-bugbear linter.
Fix is always available.
What it does
Checks for uses of
assert False
.Why is this bad?
Python removes
assert
statements when running in optimized mode(
python -O
), makingassert False
an unreliable means ofraising an
AssertionError
.Instead, raise an
AssertionError
directly.Example
Use instead:
References
assert
abstract-base-class-without-abstract-method (B024)
Derived from the flake8-bugbear linter.
What it does
Checks for abstract classes without abstract methods.
Why is this bad?
Abstract base classes are used to define interfaces. If they have no abstract
methods, they are not useful.
If the class is not meant to be used as an interface, it should not be an
abstract base class. Remove the
ABC
base class from the class definition,or add an abstract method to the class.
Example
Use instead:
References
abc
unnecessary-generator-set (C401)
Derived from the flake8-comprehensions linter.
Fix is always available.
What it does
Checks for unnecessary generators that can be rewritten as
set
comprehensions.
Why is this bad?
It is unnecessary to use
set
around a generator expression, sincethere are equivalent comprehensions for these types. Using a
comprehension is clearer and more idiomatic.
Examples
Use instead:
unnecessary-collection-call (C408)
Derived from the flake8-comprehensions linter.
Fix is always available.
What it does
Checks for unnecessary
dict
,list
ortuple
calls that can berewritten as empty literals.
Why is this bad?
It's unnecessary to call e.g.,
dict()
as opposed to using an emptyliteral (
{}
). The former is slower because the namedict
must belooked up in the global scope in case it has been rebound.
Examples
Use instead:
unnecessary-call-around-sorted (C413)
Derived from the flake8-comprehensions linter.
Fix is always available.
What it does
Checks for unnecessary
list
orreversed
calls aroundsorted
calls.
Why is this bad?
It is unnecessary to use
list
aroundsorted
, as the latter alreadyreturns a list.
It is also unnecessary to use
reversed
aroundsorted
, as the latterhas a
reverse
argument that can be used in lieu of an additionalreversed
call.In both cases, it's clearer to avoid the redundant call.
Examples
Use instead:
unnecessary-double-cast-or-process (C414)
Derived from the flake8-comprehensions linter.
Fix is always available.
What it does
Checks for unnecessary
list
,reversed
,set
,sorted
, andtuple
call within
list
,set
,sorted
, andtuple
calls.Why is this bad?
It's unnecessary to double-cast or double-process iterables by wrapping
the listed functions within an additional
list
,set
,sorted
, ortuple
call. Doing so is redundant and can be confusing for readers.Examples
Use instead:
This rule applies to a variety of functions, including
list
,reversed
,set
,sorted
, andtuple
. For example:list(list(iterable))
, uselist(iterable)
.list(tuple(iterable))
, uselist(iterable)
.tuple(list(iterable))
, usetuple(iterable)
.tuple(tuple(iterable))
, usetuple(iterable)
.set(set(iterable))
, useset(iterable)
.set(list(iterable))
, useset(iterable)
.set(tuple(iterable))
, useset(iterable)
.set(sorted(iterable))
, useset(iterable)
.set(reversed(iterable))
, useset(iterable)
.sorted(list(iterable))
, usesorted(iterable)
.sorted(tuple(iterable))
, usesorted(iterable)
.sorted(sorted(iterable))
, usesorted(iterable)
.sorted(reversed(iterable))
, usesorted(iterable)
.unnecessary-comprehension (C416)
Derived from the flake8-comprehensions linter.
Fix is always available.
What it does
Checks for unnecessary
dict
,list
, andset
comprehension.Why is this bad?
It's unnecessary to use a
dict
/list
/set
comprehension to build adata structure if the elements are unchanged. Wrap the iterable with
dict()
,list()
, orset()
instead.Examples
Use instead:
unnecessary-map (C417)
Derived from the flake8-comprehensions linter.
Fix is sometimes available.
What it does
Checks for unnecessary
map
calls withlambda
functions.Why is this bad?
Using
map(func, iterable)
whenfunc
is alambda
is slower thanusing a generator expression or a comprehension, as the latter approach
avoids the function call overhead, in addition to being more readable.
Examples
Use instead:
This rule also applies to
map
calls withinlist
,set
, anddict
calls. For example:
list(map(lambda num: num * 2, nums))
, use[num * 2 for num in nums]
.set(map(lambda num: num % 2 == 0, nums))
, use{num % 2 == 0 for num in nums}
.dict(map(lambda v: (v, v ** 2), values))
, use{v: v ** 2 for v in values}
.Does this work well for both Cloud and self-hosted?
No impact
How did you test this code?