mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 12:30:13 +03:00
Add memory: import validation best practice
This commit is contained in:
parent
7d8ab399da
commit
8ef70d9fac
@ -31,3 +31,6 @@
|
||||
### MCP Service
|
||||
- **[MCP Service Design](./mcp-service-design.md)** - MCP (Model Context Protocol) service architecture using FastMCP with SSE transport, JWT auth, 29 tools across 5 domains
|
||||
- **[MCP Tool Description Location](./mcp-tool-description-guide.md)** - Where to define MCP tool descriptions: in `@mcp.tool()` functions in `__init__.py`, not in `*_TOOLS` arrays
|
||||
|
||||
### Python Code Verification
|
||||
- **[Import Validation](./python-import-validation.md)** - Use actual module imports (`python -c "from ... import ..."`) instead of `py_compile` to catch missing imports
|
||||
|
||||
30
.claude/memory/python-import-validation.md
Normal file
30
.claude/memory/python-import-validation.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Python Import Validation
|
||||
|
||||
## Background
|
||||
|
||||
When checking if modified Python code is correct, `py_compile` only validates syntax (e.g., balanced parentheses, valid keywords). It does **not** catch missing imports or other runtime errors (e.g., using `UUID()` without importing `UUID`).
|
||||
|
||||
## Decision/Implementation
|
||||
|
||||
Use actual module imports to verify code correctness:
|
||||
|
||||
```bash
|
||||
# ✅ This catches missing imports and runtime errors
|
||||
venv/bin/python -c "
|
||||
from gns3server.api.routes.controller.dependencies.authentication import get_user_from_token
|
||||
from gns3server.api.routes.mcp.__init__ import _resolve_token
|
||||
print('All imports OK')
|
||||
"
|
||||
|
||||
# ❌ This only checks syntax, not references
|
||||
venv/bin/python -c "import py_compile; py_compile.compile('file.py', doraise=True)"
|
||||
```
|
||||
|
||||
## Related Files
|
||||
|
||||
`gns3server/api/routes/controller/dependencies/authentication.py` — missed `from uuid import UUID`
|
||||
`gns3server/api/routes/mcp/__init__.py` — missed `from uuid import UUID`
|
||||
|
||||
## Why
|
||||
|
||||
A `NameError` at runtime is far more expensive than a failed import check. Real import testing catches the full dependency chain.
|
||||
Loading…
x
Reference in New Issue
Block a user