| name | clean-names |
| description | Use when naming, renaming, or fixing names of variables, functions, classes, or modules in Python. Enforces Clean Code principles—descriptive names, appropriate length, no encodings. |
| when_to_use | Also trigger on: single-letter or cryptic identifiers (`d`, `x`, `proc`), Hungarian notation (`str_name`, `lst_users`, `i_count`), `I`-prefixed classes, function names that hide side effects (e.g. `get_config` that also writes a file), non-standard abbreviations, or asks like "rename this", "what does this variable mean", "clearer name".
|
Clean Names
N1: Choose Descriptive Names
Names should reveal intent. If a name requires a comment, it doesn't reveal its intent.
d = 86400
SECONDS_PER_DAY = 86400
def proc(lst):
return [x for x in lst if x > 0]
def filter_positive_numbers(numbers):
return [n for n in numbers if n > 0]
N2: Choose Names at the Appropriate Level of Abstraction
Don't pick names that communicate implementation; choose names that reflect the level of abstraction of the class or function.
def get_dict_of_user_ids_to_names():
...
def get_user_directory():
...
N3: Use Standard Nomenclature Where Possible
Use terms from the domain, design patterns, or well-known conventions.
class UserFactory:
def create(self, data): ...
def calculate_amortization(principal, rate, term): ...
N4: Unambiguous Names
Choose names that make the workings of a function or variable unambiguous.
def rename(old, new):
...
def rename_file(old_path: Path, new_path: Path):
...
N5: Use Longer Names for Longer Scopes
Short names are fine for tiny scopes. Longer scopes need longer, more descriptive names.
total = sum(x for x in numbers)
MAX_RETRY_ATTEMPTS_BEFORE_FAILURE = 5
MAX = 5
N6: Avoid Encodings
Don't encode type or scope information into names. Modern editors make this unnecessary.
str_name = "Alice"
lst_users = []
i_count = 0
name = "Alice"
users = []
count = 0
class IUserRepository:
...
class UserRepository:
...
N7: Names Should Describe Side Effects
If a function does something beyond what its name suggests, the name is misleading.
def get_config():
if not config_path.exists():
config_path.write_text("{}")
return json.loads(config_path.read_text())
def get_or_create_config():
if not config_path.exists():
config_path.write_text("{}")
return json.loads(config_path.read_text())
Quick Reference
| Rule | Principle | Example |
|---|
| N1 | Descriptive names | SECONDS_PER_DAY not d |
| N2 | Right abstraction level | get_user_directory() not get_dict_of_... |
| N3 | Standard nomenclature | UserFactory, calculate_amortization |
| N4 | Unambiguous | rename_file(old_path, new_path) |
| N5 | Length matches scope | Short for loops, long for globals |
| N6 | No encodings | users not lst_users |
| N7 | Describe side effects | get_or_create_config() |