Commit 59c96b9
authored
[FIX]: Fix async context manager protocol typing (#119)
## Description
`ty` (>=0.59.0, as seen in #118) rejects `Session` and `InjectionHandle`
when they are passed to `AsyncExitStack.enter_async_context`.
Both protocols inherit their context manager methods from
`AbstractAsyncContextManager`, but also redeclare `__aenter__` using
`Self`. That leaves `ty` trying to reconcile two recursive versions of
the same signature.
This removes the duplicate `__aenter__` and `__aexit__` declarations and
relies on the inherited signatures instead. `Session` now specifies
`None` as its exit return type, preserving the previous cleanup
contract.
The XPIA call sites do not need to change.
Validation:
- `uv run ty check`
- `uv run pytest tests/unit/core/test_adapter.py
tests/unit/core/test_injection.py tests/unit/attacks/test_xpia.py`
- `uv run pre-commit run --all-files`
## Breaking changes
None.
## Checklist
- [x] `pre-commit run --all-files` passes
- [ ] Tests added or updated for changes (existing protocol and XPIA
tests cover the affected behavior)
- [x] Documentation updated1 parent 1a67e72 commit 59c96b9
2 files changed
Lines changed: 8 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
23 | | - | |
| 21 | + | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | | - | |
28 | | - | |
| 25 | + | |
| 26 | + | |
29 | 27 | | |
30 | 28 | | |
31 | 29 | | |
| |||
46 | 44 | | |
47 | 45 | | |
48 | 46 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 47 | | |
64 | 48 | | |
65 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
31 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 54 | | |
70 | 55 | | |
71 | 56 | | |
| |||
0 commit comments