Skip to content

Commit 8394d7f

Browse files
committed
udpate instrcutions on aiohttp
1 parent 03ebdb3 commit 8394d7f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

.github/instructions/python.instructions.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Ensure compatibility with the following library versions:
3535

3636
* Use `f-string` formatting for all string interpolation except for logging message strings.
3737
* Use **relative imports** within the same package/module.
38+
- For imports within the same repository/project, always use relative imports (e.g., `from ..constants import APP_SETTINGS_KEY` instead of `from simcore_service_webserver.constants import APP_SETTINGS_KEY`)
39+
- Use absolute imports only for external libraries and packages
3840
* Place **all imports at the top** of the file.
3941
* Document functions when the code is not self-explanatory or if asked explicitly.
4042

@@ -44,6 +46,18 @@ Ensure compatibility with the following library versions:
4446
* Prefer `json_dumps` / `json_loads` from `common_library.json_serialization` instead of the built-in `json.dumps` / `json.loads`.
4547
* When using Pydantic models, prefer methods like `model.model_dump_json()` for serialization.
4648

47-
### 7. **Running tests**
49+
### 7. **aiohttp Framework**
50+
51+
* **Application Keys**: Always use `web.AppKey` for type-safe application storage instead of string keys
52+
- Define keys with specific types: `APP_MY_KEY: Final = web.AppKey("APP_MY_KEY", MySpecificType)`
53+
- Use precise types instead of generic `object` when the actual type is known
54+
- Example: `APP_SETTINGS_KEY: Final = web.AppKey("APP_SETTINGS_KEY", ApplicationSettings)`
55+
- Store and retrieve: `app[APP_MY_KEY] = value` and `data = app[APP_MY_KEY]`
56+
* **Request Keys**: Use `web.AppKey` for request storage as well for consistency and type safety
57+
* **Middleware**: Follow the repository's middleware patterns for cross-cutting concerns
58+
* **Error Handling**: Use the established exception handling decorators and patterns
59+
* **Route Definitions**: Use `web.RouteTableDef()` and organize routes logically within modules
60+
61+
### 8. **Running tests**
4862
* Use `--keep-docker-up` flag when testing to keep docker containers up between sessions.
4963
* Always activate the python virtual environment before running pytest.

0 commit comments

Comments
 (0)