flake8-simple-var
Background
This flake8 plugin enforces the principle that variable names should contain only one word. The idea is based on the concept that compound variable names (like textLength, table_name, or current-user-email) often indicate that the scope is too large and complex, making simple nouns ambiguous.
When you need compound names, it usually means your scope is too big and complex. An ideal method should deal with up to five variables, and an ideal class should encapsulate up to five properties. If we have five variables, we should be able to find five unique single-word nouns to name them.
This approach promotes cleaner, more maintainable code by encouraging smaller, more focused scopes.
Installation
To install flake8-simple-var, you can use pip:
pip install flake8-simple-var
Usage
After installing the plugin, flake8 will automatically use it when you run the following command:
flake8 your_project_directory
The plugin will check variable names to ensure they contain only one word. If a variable name contains multiple words (camelCase, snake_case, kebab-case, etc.), an error will be reported.
Rules
The plugin checks the following types of variable names:
- SVN100: Variable names should contain only one word
- SVN200: Function argument names should contain only one word
- SVN300: Exception handler variable names should contain only one word
- SVN400: With statement variable names should contain only one word
What is considered a compound name:
textLength(camelCase)table_name(snake_case)current-user-email(kebab-case)USER_NAME(UPPER_CASE with multiple words)
What is considered valid:
x,name,value,count(single words)_private_var(private variables starting with_are ignored)__very_private(dunder names are ignored)
Examples
❌ Invalid variable names:
# These will trigger SVN errors
textLength = 10
userName = "john"
table_name = "users"
current_user_email = "test@example.com"
file_path = "/tmp/file.txt"
def process_data(user_name, file_path):
return user_name + file_path
for item_name in items:
print(item_name)
try:
pass
except ValueError as error_message:
print(error_message)
with open('file.txt') as file_handle:
content = file_handle.read()
✅ Valid variable names:
# These are valid single-word names
x = 1
name = "test"
value = 42
count = 10
user = "john"
table = "users"
email = "test@example.com"
file = "/tmp/file.txt"
def process_data(user, file):
return user + file
for item in items:
print(item)
try:
pass
except ValueError as error:
print(error)
with open('file.txt') as file:
content = file.read()
Philosophy
The principle behind this plugin is inspired by the idea that compound variable names often indicate:
- Large scope: When you need compound names, it usually means your scope (method, class, module) is too large
- Complexity: Simple nouns become ambiguous because there are too many variables in the same scope
- Poor design: If you can't find unique single-word names for your variables, consider refactoring
The goal is to encourage:
- Smaller, more focused methods and classes
- Better variable naming through context
- Cleaner, more readable code
License
Credits
This project was generated with wemake-python-package. Current template version is: 9899cb192f754a566da703614227e6d63227b933. See what is updated since then.
Metadata
Release files for flake8-simple-var 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flake8_simple_var-0.1.0.tar.gz | 5.3 kB | Without provenance | Details for flake8_simple_var-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flake8_simple_var-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for flake8_simple_var-0.1.0-py3-none-any.whl |
Total release size: 13.6 kB
Release files / flake8_simple_var-0.1.0.tar.gz
| Download URL | flake8_simple_var-0.1.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d38f6447e285a56fce46dfa21d3dc816ba8de1b2faeb37b62289af2c8cbfffce
|
|
BLAKE2b-256 checksum How to use checksums |
c522a1ee373617ab0886f576d208f780de5656aadf4a1abb256d4b093b1eda16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.0 Darwin/24.3.0
|
Release files / flake8_simple_var-0.1.0-py3-none-any.whl
| Download URL | flake8_simple_var-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b58fa4c4c0385a6c04d9fe816251f038cc39db07e0a97a0cee5bf9dadf1556af
|
|
BLAKE2b-256 checksum How to use checksums |
d3d8d020003ba2f2aede162125a84f4cd5fec0786f413aaaa69c5e7dad57c1be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.0 Darwin/24.3.0
|
Security for flake8-simple-var 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.