You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/instructions/python.instructions.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,8 @@ Ensure compatibility with the following library versions:
35
35
36
36
* Use `f-string` formatting for all string interpolation except for logging message strings.
37
37
* 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
38
40
* Place **all imports at the top** of the file.
39
41
* Document functions when the code is not self-explanatory or if asked explicitly.
40
42
@@ -44,6 +46,18 @@ Ensure compatibility with the following library versions:
44
46
* Prefer `json_dumps` / `json_loads` from `common_library.json_serialization` instead of the built-in `json.dumps` / `json.loads`.
45
47
* When using Pydantic models, prefer methods like `model.model_dump_json()` for serialization.
46
48
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**
48
62
* Use `--keep-docker-up` flag when testing to keep docker containers up between sessions.
49
63
* Always activate the python virtual environment before running pytest.
0 commit comments