Flake8 Variables Names
Flake8 Variables Names is a Flake8 extension designed to promote more readable variable names in Python code. It identifies single-character variable names or overly common and ambiguous names such as 'result', 'value', or 'info', flagging them for clarification. The current version is 0.0.6, with releases occurring periodically to introduce new features and fix bugs.
Warnings
- breaking In version `0.0.6`, a bug fix changed the behavior for multiple assignments. Expressions like `a, b = 1, 2` are now correctly marked as invalid if `a` or `b` violate naming conventions.
- gotcha By default, `flake8-variables-names` operates in a 'non-strict' mode. This means some common but ambiguous variable names (e.g., 'data', 'result', 'value') are not flagged unless 'strict mode' is explicitly enabled.
- gotcha The plugin introduces specific error codes (VNE001, VNE002, VNE003) for various naming violations. Not understanding these codes can make it difficult to interpret `flake8`'s output.
Install
-
pip install flake8-variables-names
Imports
- VariableNamesChecker
This is a Flake8 plugin and typically doesn't require direct imports in user code for its core functionality. It is automatically loaded by Flake8 upon installation. For programmatic access to its version, you might import from `flake8_variables_names`.
Quickstart
# 1. Install the library # pip install flake8 flake8-variables-names # 2. Create a Python file, e.g., my_module.py # def process_data(d): # i = 0 # res = d * 2 # info = 'processed' # return res, info # 3. Run flake8 on your file or project # flake8 my_module.py # Example of flake8 output: # my_module.py:2:13: VNE001 single letter variable names like 'd' are not allowed # my_module.py:3:5: VNE001 single letter variable names like 'i' are not allowed # my_module.py:4:5: VNE002 variable name 'res' should be clarified # my_module.py:5:5: VNE002 variable name 'info' should be clarified # 4. To enable strict mode (more aggressive checks): # flake8 --use-varnames-strict-mode my_module.py # Or in a config file (setup.cfg, tox.ini, or .flake8): # [flake8] # use-varnames-strict-mode = True