Packages
nous
0.16.5
0.17.0
0.16.6
0.16.5
0.16.4
0.16.3
0.16.2
0.16.1
0.16.0
0.15.8
0.15.7
0.15.6
0.15.5
0.15.4
0.15.3
0.15.2
0.15.1
0.15.0
0.14.3
0.14.2
0.14.1
0.14.0
0.13.3
0.13.2
0.13.1
0.13.0
0.12.17
0.12.16
0.12.15
0.12.14
0.12.13
0.12.12
0.12.11
0.12.9
0.12.7
0.12.6
0.12.5
0.12.3
0.12.2
0.12.0
0.11.3
0.11.0
0.10.1
0.10.0
0.9.0
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.5.0
AI agent framework for Elixir with multi-provider LLM support
Current section
Files
Jump to
Current section
Files
lib/nous/skills/python_typing.ex
defmodule Nous.Skills.PythonTyping do
@moduledoc "Built-in skill for modern Python type hints, Pydantic, and dataclasses."
use Nous.Skill, tags: [:python, :typing, :pydantic, :modern], group: :coding
@impl true
def name, do: "python_typing"
@impl true
def description,
do: "Modern Python: type hints, Protocol classes, Pydantic vs dataclasses, pattern matching"
@impl true
def instructions(_agent, _ctx) do
"""
You are a modern Python specialist (3.10+). Follow these patterns:
1. **Type annotations on all public functions**: Use `mypy --strict` compatible annotations:
```python
def process_items(items: list[str], limit: int = 10) -> dict[str, int]:
```
2. **Choose the right data container**:
- `Pydantic BaseModel`: API boundaries, runtime validation needed
- `@dataclass`: Internal data, trust input, no validation
- `TypedDict`: Typed dictionaries without class overhead
- `Protocol`: Structural subtyping (duck typing with types)
3. **Protocol classes** for interfaces (not ABC):
```python
class Renderable(Protocol):
def render(self) -> str: ...
```
4. **Pattern matching** (3.10+) for complex branching:
```python
match command:
case {"action": "create", "data": data}:
create(data)
case {"action": "delete", "id": int(id)}:
delete(id)
case _:
raise ValueError("Unknown command")
```
5. **Use `|` union syntax** (3.10+): `str | None` not `Optional[str]`.
6. **Pydantic v2 patterns**:
```python
class Config(BaseModel):
model_config = ConfigDict(validate_assignment=True, from_attributes=True)
```
7. **Naming**: `snake_case` functions/variables, `PascalCase` classes, `UPPER_CASE` constants.
8. **Google-style docstrings** for all public APIs with type descriptions.
"""
end
@impl true
def match?(input) do
input = String.downcase(input)
String.contains?(input, [
"python type",
"type hint",
"pydantic",
"dataclass",
"protocol class",
"pattern matching python",
"mypy"
])
end
end