mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-04-23 01:56:37 +00:00
Sync .cursor from detections
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
description: "Python coding conventions: PEP 8, type hints, pydantic, pytest, async patterns, project structure"
|
||||
globs: ["**/*.py", "**/pyproject.toml", "**/requirements*.txt"]
|
||||
globs: ["**/*.py", "**/*.pyx", "**/*.pxd", "**/pyproject.toml", "**/requirements*.txt"]
|
||||
---
|
||||
# Python
|
||||
|
||||
@@ -8,10 +8,14 @@ globs: ["**/*.py", "**/pyproject.toml", "**/requirements*.txt"]
|
||||
- Use type hints on all function signatures; validate with `mypy` or `pyright`
|
||||
- Use `pydantic` for data validation and serialization
|
||||
- Import order: stdlib -> third-party -> local; use absolute imports
|
||||
- Use `src/` layout to separate app code from project files
|
||||
- Use context managers (`with`) for resource management
|
||||
- Catch specific exceptions, never bare `except:`; use custom exception classes
|
||||
- Use `async`/`await` with `asyncio` for I/O-bound concurrency
|
||||
- Use `pytest` for testing (not `unittest`); fixtures for setup/teardown
|
||||
- Use virtual environments (`venv` or `poetry`); pin dependencies
|
||||
- **NEVER install packages globally** (`pip install` / `pip3 install` without a venv). ALWAYS use a virtual environment (`venv`, `poetry`, or `conda env`). If no venv exists for the project, create one first (`python3 -m venv .venv && source .venv/bin/activate`) before installing anything. Pin dependencies.
|
||||
- Format with `black`; lint with `ruff` or `flake8`
|
||||
|
||||
## Cython
|
||||
- In `cdef class` methods, prefer `cdef` over `cpdef` unless the method must be callable from Python. `cdef` = C-only (fastest), `cpdef` = C + Python, `def` = Python-only. Check all call sites before choosing.
|
||||
- **Python cannot call `cdef` methods.** If a `.py` file needs to call a `cdef` method on a Cython object, there are exactly two options: (a) convert the calling file to `.pyx`, `cimport` the class, and use a typed parameter so Cython dispatches the call at the C level; or (b) change the method to `cpdef` if it genuinely needs to be callable from both Python and Cython. Never leave a bare `except Exception: pass` around such a call — it will silently swallow the `AttributeError` and make the failure invisible for a very long time.
|
||||
- When converting a `.py` file to `.pyx` to gain access to `cdef` methods: add the new extension to `setup.py`, add a `cimport` of the relevant `.pxd`, type the parameter(s) that carry the Cython object, and delete the old `.py` file. This ensures the cross-language call is resolved at compile time, not at runtime.
|
||||
|
||||
Reference in New Issue
Block a user