Here is a list of the built-in categories in Refurb, and their meanings.
These check for code relating to Abstract Base Classes.
Checks that have the builtin
category cover a few different topics:
- Built-in functions such as
print()
,open()
,str()
, and so on - Statements such as
del
- File system related operations such as
open()
andreadlines()
These checks are for the collections standard library module.
These checks deal with the control flow of a program, such as optimizing usage
of return
and continue
, removing if
statements under certain conditions,
and so on.
These checks are for the contextlib standard library module.
These checks are for the datetime standard library module.
These checks are for the decimal standard library module.
These checks cover:
- Usage of
dict
objects - In some cases, objects supporting the Mapping protocol
These are checks relating to the third-party FastAPI library.
These checks relate to Python's f-strings.
These checks are for the fractions standard library module.
These checks relate to the functools standard library module.
These checks relate to the hashlib standard library module.
These checks cover:
- Iterable types such as
list
andtuple
- Standard library objects which are commonly iterated over such as
dict
keys
These checks relate to the itertools standard library module.
These checks relate to the math standard library module.
These checks relate to the operator standard library module.
These checks relate to logical cleanups and optimizations, primarily in if
statements,
but also in boolean expressions.
These checks cover usage of the built-in list
object.
Checks related to Python 3.10's Structural Pattern Matching.
These checks relate to the pathlib standard library module.
These checks are supposted to find slow code that can be written faster. The threshold for
"fast" and "slow" are somewhat arbitrary and depend on the check, but in general you should
expect that a check in the performance
category will make your code faster (and should never
make it slower).
These checks are only enabled for Python versions 3.9, 3.10, or 3.11 respectively, or in some
way are improved in later versions of Python. For example, isinstance(x, y) or isinstance(x, z)
can be written as isinstance(x, (y, z))
in any Python version, but in Python 3.10+ it can
be written as isinstance(x, y | z)
.
This is a general catch-all for things which are "unpythonic". It differs from the
readability
category because "unreadable" code can still be pythonic.
These checks aim to make existing code more readable. This can be subjective, but in general, they reduce the horizontal or vertical length of your code, or make the underlying meaning of the code more apparent.
These checks are for the re
standard library module.
These checks have to do with Python's scoping rules. For more info on how Python's scoping rules work, read this article.
These checks are for the secrets standard library module.
These checks deal with usage of set
objects in Python.
These checks are for the shlex standard library module.
These checks deal with usage of str
objects in Python.
These checks cover truthy and falsy operations in Python, primarily in the context of assert
and if
statements.