rename_symbol¶
Rename a function, class, or method in a file and optionally update all references across the project.
Quick Reference¶
rename_symbol(
file_path: str, # Path to file
target_type: str, # "function", "class", "method"
target_name: str, # Current name
new_name: str, # New name
create_backup: bool = True # Create backup
) -> RenameResult
User Stories¶
| Persona | Story | Tool Value |
|---|---|---|
| 👥 David (Team Lead) | "Rename symbols consistently across the codebase" | Refactoring safety |
| 🔧 Chris (OSS Contributor) | "Improve code clarity through safe renaming" | Code quality |
| 👤 Sarah (AI User) | "Update naming conventions without manual search-replace risks" | Automated refactoring |
Parameters¶
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file_path | string | Yes | - | Absolute path to file |
target_type | string | Yes | - | "function", "class", or "method" |
target_name | string | Yes | - | Current symbol name |
new_name | string | Yes | - | New symbol name |
create_backup | bool | No | true | Create backup before renaming |
Response Schema¶
{
"data": {
"file_path": "string",
"target_type": "string",
"old_name": "string",
"new_name": "string",
"status": "string",
"backup_path": "string | null",
"references_updated": "integer",
"files_modified": ["string"]
},
"error": null,
"tier_applied": "string",
"duration_ms": "integer"
}
Examples¶
Rename a Function¶
Rename a Class¶
Rename a Method¶
Rename Without Backup¶
Naming Conventions¶
The tool validates that new names follow Python conventions:
| Symbol Type | Convention | Example |
|---|---|---|
| Function | snake_case | calculate_total |
| Class | PascalCase | UserService |
| Method | snake_case | get_user_by_id |
| Private | Leading underscore | _internal_method |
| Constant | UPPER_SNAKE | MAX_RETRIES |
Tier Limits¶
rename_symbol capabilities vary by tier:
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Max files searched | 0 (single file) | 500 | Unlimited |
| Max files updated | 0 (single file) | 200 | Unlimited |
| Single file rename | ✅ | ✅ | ✅ |
| Backup creation | ✅ | ✅ | ✅ |
| Cross-file updates | ❌ | ✅ | ✅ |
| Project-wide rename | ❌ | ✅ | ✅ |
| Import auto-update | ❌ | ✅ | ✅ |
| Reference tracking | ❌ | ✅ | ✅ Full |
Community Tier¶
- ✅ Rename functions, classes, methods in a single file
- ✅ Automatic backup creation
- ✅ Naming convention validation
- ✅ Conflict detection
- ⚠️ Single file only - Won't update references in other files
- ⚠️ No import updates - Imports remain unchanged
- ❌ No project-wide rename capability
Pro Tier¶
- ✅ All Community features
- ✅ Search up to 500 files - Find all references
- ✅ Update up to 200 files - Project-wide rename
- ✅ Auto-update imports - Fix import statements
- ✅ Reference tracking - See what gets updated
- ✅ Preview mode - See changes before applying
Enterprise Tier¶
- ✅ All Pro features
- ✅ Unlimited file search/update - Organization-wide rename
- ✅ Full reference tracking - Complete impact analysis
- ✅ Multi-repository rename - Rename across repos
- ✅ Approval workflows - Require team review
- ✅ Audit trail - Track all renames
Key Difference: Scope of Rename - Community: Single file only - Rename in isolation - Pro: 500 files searched, 200 updated - Project-wide refactoring - Enterprise: Unlimited - Organization-wide rename
Error Handling¶
Symbol Not Found¶
{
"data": null,
"error": {
"code": "SYMBOL_NOT_FOUND",
"message": "Function 'calc_totl' not found in utils.py",
"suggestions": ["calc_total", "calculate_total"]
}
}
Invalid Name¶
{
"data": null,
"error": {
"code": "INVALID_NAME",
"message": "'123_function' is not a valid Python identifier",
"suggestion": "Names must start with letter or underscore"
}
}
Name Conflict¶
{
"data": null,
"error": {
"code": "NAME_CONFLICT",
"message": "Symbol 'calculate_total' already exists in utils.py",
"existing_symbol": {
"type": "function",
"line": 45
}
}
}
Best Practices¶
- Check references first - Use
get_symbol_referencesbefore renaming - Follow conventions - Use appropriate case for symbol type
- Keep backups - Easy rollback if issues
- Update tests - Rename in tests too
- Update docs - API documentation may reference old name
Workflow¶
graph TD
A[get_symbol_references] --> B{Many references?}
B -->|Yes| C[Plan carefully]
B -->|No| D[rename_symbol]
C --> D
D --> E[Run tests]
E -->|Pass| F[Update docs]
E -->|Fail| G[Check references] Related Tools¶
- get_symbol_references - Find all usages first
- update_symbol - Replace code instead
- analyze_code - Find symbols to rename