Skip to content

Commit f21228a

Browse files
committed
chore: update agents.md
1 parent a40fd89 commit f21228a

3 files changed

Lines changed: 69 additions & 13 deletions

File tree

.agents/skills/socketio-stub-updater/SKILL.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ git diff <OLD_TAG>..<NEW_TAG> -- 'src/socketio/*.py' | grep -E '^\+.*def |^\-.*d
9898

9999
For each identified change, update the corresponding `.pyi` file:
100100

101+
### Generic Type Parameters
102+
103+
This repository targets Python 3.12+. Prefer PEP 695 syntax for generic stubs instead of adding direct `TypeVar` or `ParamSpec` declarations:
104+
105+
```python
106+
from collections.abc import Callable
107+
108+
class Result[T]:
109+
def unwrap(self) -> T: ...
110+
111+
def decorator[**P, T](func: Callable[P, T]) -> Callable[P, T]: ...
112+
```
113+
114+
Use direct `TypeVar`/`ParamSpec` only when required by syntax limitations. In particular, keep direct `TypeVar(..., default=...)` for type parameter defaults because default values in type parameter syntax require Python 3.13+.
115+
116+
Name PEP 695 parameters without leading underscores (`T`, `P`). If a direct `TypeVar`/`ParamSpec` is required, use underscored variables such as `_T` or `_P`.
117+
101118
### Adding New Function
102119

103120
```python

.agents/skills/socketio-stub-updater/references/REFERENCE.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,37 @@ def process(data: str | bytes | list[int]) -> str | bytes | list[int]: ...
6767

6868
### Generic Types
6969

70-
```python
71-
from typing import TypeVar, Generic
72-
from collections.abc import Callable, Iterator
70+
Prefer Python 3.12 type parameter syntax for generic stubs:
7371

74-
T = TypeVar("T")
75-
T_co = TypeVar("T_co", covariant=True)
72+
```python
73+
from collections.abc import Callable
7674

77-
class Container(Generic[T]):
75+
class Container[T]:
7876
def get(self) -> T: ...
7977
def set(self, value: T) -> None: ...
8078

8179
# Callable types
8280
def apply(func: Callable[[int, str], bool], x: int, y: str) -> bool: ...
8381

84-
# With ParamSpec for decorators
85-
from typing import ParamSpec, Concatenate
82+
# Decorators can use ParamSpec syntax without a direct ParamSpec declaration
83+
def decorator[**P, T](func: Callable[P, T]) -> Callable[P, T]: ...
84+
```
8685

87-
P = ParamSpec("P")
86+
Use direct `TypeVar`/`ParamSpec` only when the 3.12 type parameter syntax cannot express the type. The most common required case in this repository is `default=`, because type parameter defaults are only syntax-supported in Python 3.13+:
8887

89-
def decorator(func: Callable[P, T]) -> Callable[P, T]: ...
88+
```python
89+
from typing import Generic, Literal
90+
from typing_extensions import TypeVar
91+
92+
_IsAsyncio = TypeVar("_IsAsyncio", bound=bool, default=Literal[False])
93+
94+
class BaseNamespace(Generic[_IsAsyncio]): ...
9095
```
9196

97+
Naming convention:
98+
- PEP 695 syntax: use `T`, `P` (not `_T`, `_P`)
99+
- Direct `TypeVar`/`ParamSpec`: use `_T`, `_P`
100+
92101
## Module Organization
93102

94103
### `__init__.pyi` Pattern
@@ -276,8 +285,10 @@ from typing import (
276285
overload,
277286
)
278287

279-
# Use typing_extensions for ParamSpec, TypeVar (for compatibility)
280-
from typing_extensions import ParamSpec, TypeVar
288+
# Prefer Python 3.12 type parameter syntax for generics.
289+
# Import TypeVar/ParamSpec from typing_extensions only when direct declarations
290+
# are required, such as TypeVar(..., default=...).
291+
from typing_extensions import TypeVar
281292

282293
# Absolute imports from socketio modules
283294
from socketio._types import CustomType # Internal types
@@ -292,7 +303,6 @@ from typing import Any, overload
292303
from socketio._types import HandlerType, Namespace
293304
from socketio.base_server import BaseServer
294305
```
295-
```
296306

297307
## Deprecation Handling
298308

AGENTS.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,35 @@ src/
3232
3. Use `as` syntax for re-exports: `from mod import X as X`
3333
4. Define internal types in `_types.pyi`
3434
5. Avoid `Incomplete` - use concrete types
35+
6. Prefer Python 3.12 type parameter syntax over direct `TypeVar`/`ParamSpec` declarations unless direct declarations are required
36+
37+
### Generic Type Parameters
38+
39+
This repository targets Python 3.12+. Prefer PEP 695 type parameter syntax for new generic stubs:
40+
41+
```python
42+
from collections.abc import Callable
43+
44+
class Box[T]:
45+
def get(self) -> T: ...
46+
47+
def decorator[**P, T](func: Callable[P, T]) -> Callable[P, T]: ...
48+
```
49+
50+
Use direct `TypeVar`/`ParamSpec` only when the 3.12 syntax cannot express the type. The main required case is a type parameter default, because default values for type parameters are only supported by syntax in Python 3.13+:
51+
52+
```python
53+
from typing import Generic, Literal
54+
from typing_extensions import TypeVar
55+
56+
_IsAsyncio = TypeVar("_IsAsyncio", bound=bool, default=Literal[False])
57+
58+
class BaseNamespace(Generic[_IsAsyncio]): ...
59+
```
60+
61+
Naming convention:
62+
- PEP 695 syntax: use non-underscored names (`T`, `P`), not `_T`/`_P`
63+
- Direct `TypeVar`/`ParamSpec`: keep underscored variables (`_T`, `_P`)
3564

3665
**⚠️ Updating Stubs**: For stub updates or new module additions, use the `socketio-stub-updater` skill located in `.agents/skills/socketio-stub-updater/SKILL.md`
3766

0 commit comments

Comments
 (0)