fix: protect critical re-export imports from linter removal

Problem:
- Ruff removed 'from app.core.database import Base' from models/database/base.py
- Import appeared "unused" (F401) but was actually a critical re-export
- Caused ImportError: cannot import name 'Base' at runtime
- Re-export pattern: import in one file to export from package

Solution:
1. Added F401 ignore for models/database/base.py in pyproject.toml
2. Created scripts/verify_critical_imports.py verification script
3. Integrated verification into make check and CI pipeline
4. Updated documentation with explanation

New Verification Script:
- Checks all critical re-export imports exist
- Detects import variations (parentheses, 'as' clauses)
- Handles SQLAlchemy declarative_base alternatives
- Runs as part of make check automatically

Protected Files:
- models/database/base.py - Re-exports Base for all models
- models/__init__.py - Exports Base for Alembic
- models/database/__init__.py - Exports Base from package
- All __init__.py files (already protected)

Makefile Changes:
- make verify-imports - Run import verification
- make check - Now includes verify-imports
- make ci - Includes verify-imports in pipeline

Documentation Updated:
- Code quality guide explains re-export protection
- Pre-commit workflow includes verification
- Examples of why re-exports matter

This prevents future issues where linters remove seemingly
"unused" imports that are actually critical for application structure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-28 20:10:22 +01:00
parent 4279c458c4
commit b8a46e1746
35 changed files with 200 additions and 64 deletions

View File

@@ -190,7 +190,7 @@ show_missing = true
Before committing code:
```bash
# 1. Format and lint your code
# 1. Format, lint, and verify critical imports
make check
# 2. Run relevant tests
@@ -201,6 +201,25 @@ git add .
git commit -m "your message"
```
### Critical Import Verification
The `make check` command includes a critical import verification step that ensures re-export imports haven't been removed by linters.
**What it checks:**
- `models/database/base.py` - Re-exports Base from app.core.database
- `models/__init__.py` - Exports Base for Alembic
- `models/database/__init__.py` - Exports Base from database package
**Why it matters:**
Linters like Ruff may see these imports as "unused" (F401) because they're re-exported, not directly used. Removing them breaks the application.
**Manual verification:**
```bash
make verify-imports
```
If this fails, imports have been removed and must be restored.
## CI/CD Integration
For continuous integration: