PyFlakes checks Python source files for errors, looking for potential bugs and style issues without executing the code, detecting unused imports, undefined variables, and returns in initializer functions.
PyFlakes is an open-source tool for analyzing Python code to detect errors and potential issues. It performs static analysis on Python source code by parsing the code without executing it, allowing PyFlakes to check for all kinds of bugs and style issues:
- Unused imports - imports that are not used in the code
- Undefined names - using variables/functions before they are defined
- Redefinitions - defining a variable or function twice
- Unknown names - using variables/functions that are not defined anywhere
- Shadowing names - defining a local variable that shadows a name from an outer scope
- Returns with arguments inside __init__ - return statements in object initializer functions
- Continue/Break/Return outside loops - using these flow control statements improperly
- Unreachable code - code that can never be executed
By performing static analysis, PyFlakes is fast, lightweight, and avoids the overheads of executing the full program just to check for issues. It is commonly used alongside other Python linting/analysis tools like Pylint to enforce coding standards and best practices.
Here are some alternatives to PyFlakes:
Suggest an alternative ❐