domains / app-frameworks / pallets/flask
PEP8-compliant, semantically accurate naming
All identifiers (functions, variables, parameters, methods) must follow PEP8 casing rules and clearly reflect what they actually represent or do. Specifically:
All identifiers (functions, variables, parameters, methods) must follow PEP8 casing rules and clearly reflect what they actually represent or do. Specifically:
- Use
snake_casefor functions and variables, nevercamelCase. For example,_isAdHocshould be_is_adhoc, andis_IPshould beis_ip. - Choose names that match the real behavior/type of the value, not a misleading or unrelated concept. A parameter named
textthat actually switches to binary mode should instead be named something likebinary, matching the semantics ofopen()’s mode flag. Likewise, a function namedis_ipthat also validates input and raises/formats errors should be renamed to reflect that broader responsibility (e.g.,validate_ip), rather than implying a simple boolean check. - Never shadow a meaningfully-named function/method with a local variable of a different type/purpose. For instance, avoid:
val = os.environ.get('FLASK_DONT_LOAD_ENV') load_dotenv = not val or val in ('0', 'false', 'no') # bool now shadows the load_dotenv() functionInstead use a distinct name such as
should_load_dotenvto avoid confusing readers about whetherload_dotenvrefers to the callable or a flag. - Follow Python convention and name the first parameter of instance methods
self(notreqor other domain-specific names), even when refactoring from a standalone function into a method.
Apply these checks during review: confirm casing matches PEP8, confirm the name accurately conveys the identifier’s purpose/type, and confirm no naming collisions or shadowing occur between variables and existing functions/methods.