Loop counters that are incremented on each iteration of the loop like so:
i = 0
for animal in animals:
i += 1
print(i, animal)
can be replaced with a call to enumerate
with a suitable start index:
for i, animal in enumerate(animals, start=1):
print(i, animal)
The following simple but overly verbose code:
return True if some_boolean_expression else False
is refactored to:
return bool(some_boolean_expression)
The negated version:
return False if some_boolean_expression else True
is refactored to:
return not some_boolean_expression
Instructions for how to write a code editor plugin are now available here. As the Sourcery binary implements the Language Server Protocol it is very easy to write a plugin for a new code editor.