AgentSkillsCN

naming-conventions

本代码库遵循Python命名规范。在编写或审查Python代码时,无论是函数、类、变量还是常量,都应严格遵守这些命名规则。

SKILL.md
--- frontmatter
name: naming-conventions
version: 1.0.0
description: Python naming conventions for this codebase. Apply when writing or reviewing Python code including functions, classes, variables, and constants.
user-invocable: false

Python Naming Conventions

Apply these naming patterns when writing Python code in this repository.

Quick Reference

ElementCasePatternExample
Functionsnake_case<verb>_<noun>fetch_user, validate_input
Async functionsnake_caseasync_<verb>_<noun>async_fetch_user
Variablesnake_casedescriptiveuser_count, is_valid
ClassPascalCasenounSearchIndex, UserSession
ConstantSCREAMING_SNAKE_CASE+ FinalMAX_RETRIES: Final = 3
Private_snake_case_ prefix_cache, _validate
Type aliasPascalCasenounJsonValue, Embedding

Functions and Methods

Pattern: <verb>_<noun> in snake_case

Required Verb Prefixes

VerbWhen to useExample
get_Retrieve data already in memory or from local cacheget_user_by_id, get_config
fetch_Retrieve from external source (API, database, file system)fetch_api_data, fetch_remote_file
create_Instantiate a new objectcreate_session, create_embedding
build_Construct a complex object step-by-stepbuild_query, build_request
parse_Convert raw data into structured formatparse_json, parse_response
validate_Check correctness, return bool or raisevalidate_input, validate_schema
calculate_Compute and return a valuecalculate_score, calculate_distance
transform_Convert from one format to anothertransform_coordinates, transform_response
is_Return boolean for state checkis_valid, is_authenticated
has_Return boolean for existence checkhas_permission, has_feature

Async Functions

Required: Prefix all async functions with async_

python
# CORRECT
async def async_fetch_user(user_id: int) -> User:
    return await client.get(f"/users/{user_id}")

async def async_process_batch(items: list[Item]) -> list[Result]:
    return await asyncio.gather(*[async_process(item) for item in items])

# INCORRECT - missing async_ prefix
async def fetch_user(user_id: int) -> User:  # Bad: not clear await is needed
    ...

Variables

Pattern: snake_case with descriptive names

Required Patterns

Variable typePatternExamples
Counts<noun>_countuser_count, retry_count
Maximumsmax_<noun>max_retry_attempts, max_connections
Minimumsmin_<noun>min_threshold, min_batch_size
Boolean stateis_<adjective>is_authenticated, is_valid
Boolean existencehas_<noun>has_permission, has_feature
Dimensions/sizes<noun>_dimensions or <noun>_sizeembedding_dimensions, batch_size

Forbidden Variable Names

Never use these generic names:

  • data, info, temp, tmp, val, value
  • flag, result, response (without qualifier)
  • Single letters except in comprehensions: [x for x in items]
python
# CORRECT
user_count = len(users)
max_retry_attempts = 3
embedding_dimensions = 768
is_authenticated = True
has_valid_license = check_license(user)

# INCORRECT
data = len(users)      # Too generic
n = 3                  # Single letter

Classes

Pattern: PascalCase noun describing what it represents

python
# CORRECT
class SearchIndex: ...
class EmbeddingModel: ...
class RetryPolicy: ...
class ValidationError: ...

# INCORRECT
class Search: ...          # Verb-like, unclear purpose
class EmbModel: ...        # Abbreviation
class DoValidation: ...    # Verb phrase

Constants

Pattern: SCREAMING_SNAKE_CASE with Final type annotation

python
from typing import Final

# CORRECT
MAX_RETRY_ATTEMPTS: Final = 3
DEFAULT_TIMEOUT_SECONDS: Final[float] = 30.0
SUPPORTED_FILE_FORMATS: Final[frozenset[str]] = frozenset({"json", "csv", "parquet"})

# INCORRECT
MaxRetries = 3              # Wrong case, missing Final
max_retry_attempts = 3      # Wrong case for constant
MAX_RETRY_ATTEMPTS = 3      # Missing Final annotation

Private Members

Pattern: Single underscore _ prefix for internal implementation

python
class SearchService:
    def __init__(self, index: VectorIndex) -> None:
        self._index = index              # Private attribute
        self._cache: dict[str, Result] = {}  # Private attribute

    def search(self, query: str) -> list[Result]:  # Public API
        return self._perform_search(query)

    def _perform_search(self, query: str) -> list[Result]:  # Private method
        ...

Type Aliases

Pattern: PascalCase describing the type

python
# CORRECT
JsonValue = dict[str, Any] | list[Any] | str | int | float | bool | None
Embedding = list[float]
UserId = int

# INCORRECT
json_value = dict[str, Any] | list[Any] | str | int | float | bool | None  # Wrong case