Skip to content

Commit efd3a5b

Browse files
avivlclaude
andcommitted
feat(agents): enforce mandatory strong typing across all Python agents - @python-hyx-resilience @Django-Expert @fastapi-expert @machine-learning-engineer
- Add mandatory strong typing requirements to all Python agents - Implement comprehensive typing standards: * All function parameters and return types explicitly typed * String literals use Literal["value"] for constants or str for variables * Collections use generic types: list[str], dict[str, int], etc. * Optional types use Optional[T] or T | None * Union types explicit: Union[str, int] or str | int - Framework-specific typing enhancements: * python-hyx-resilience: Async/await typing patterns with examples * django-expert: Django model fields with django-stubs integration * fastapi-expert: Pydantic models with strict field typing * machine-learning-engineer: NumPy arrays and pandas DataFrame typing - Add strong typing examples section with ✅ GOOD vs ❌ BAD patterns - Update implementation checklists to include strong typing verification - Maintain zero Pyright errors requirement with enhanced type safety - Enforce strong typing as mandatory quality standard alongside Pyright 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6a1f39a commit efd3a5b

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

.claude/agents/ai/machine-learning-engineer.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ pyright src/models/classifier.py src/data/preprocessing.py notebooks/experiment.
3737
- Zero Pyright errors allowed on changed files
3838
- All ML functions, classes, data pipelines must have proper type hints
3939
- Use typing for NumPy arrays, pandas DataFrames, model objects
40+
- **MANDATORY: Use strong typing throughout**:
41+
- All function parameters and return types explicitly typed
42+
- String literals use `Literal["value"]` for constants or `str` for variables
43+
- Collections use generic types: `list[str]`, `dict[str, int]`, etc.
44+
- Optional types use `Optional[T]` or `T | None`
45+
- Union types explicit: `Union[str, int]` or `str | int`
46+
- NumPy arrays: `np.ndarray[Any, np.dtype[np.float64]]` or `npt.NDArray[np.float64]`
47+
- Pandas DataFrames: `pd.DataFrame` with column typing when possible
4048
- Add `# type: ignore` comments only when absolutely necessary with explanation
4149

4250
### Additional Quality Tools for ML Projects

.claude/agents/backend/django-expert.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ pyright models.py views.py serializers.py
119119
- Zero Pyright errors allowed on changed files
120120
- All Django models, views, serializers must have proper type hints
121121
- Use `django-stubs` for Django-specific type hints
122+
- **MANDATORY: Use strong typing throughout**:
123+
- All function parameters and return types explicitly typed
124+
- String literals use `Literal["value"]` for constants or `str` for variables
125+
- Collections use generic types: `list[str]`, `dict[str, int]`, etc.
126+
- Optional types use `Optional[T]` or `T | None`
127+
- Union types explicit: `Union[str, int]` or `str | int`
128+
- Django model fields properly typed with `django-stubs`
122129
- Add `# type: ignore` comments only when absolutely necessary with explanation
123130

124131
### Additional Quality Tools for Django

.claude/agents/backend/fastapi-expert.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ pyright app/main.py app/models.py app/routers/users.py
106106
- Zero Pyright errors allowed on changed files
107107
- All FastAPI routes, models, dependencies must have proper type hints
108108
- Use Pydantic models for automatic type validation
109+
- **MANDATORY: Use strong typing throughout**:
110+
- All function parameters and return types explicitly typed
111+
- String literals use `Literal["value"]` for constants or `str` for variables
112+
- Collections use generic types: `list[str]`, `dict[str, int]`, etc.
113+
- Optional types use `Optional[T]` or `T | None`
114+
- Union types explicit: `Union[str, int]` or `str | int`
115+
- Pydantic models with strict field typing
109116
- Add `# type: ignore` comments only when absolutely necessary with explanation
110117

111118
### Additional Quality Tools for FastAPI

.claude/agents/backend/python-hyx-resilience.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ You are a Python resilience engineering specialist with deep expertise in Hyx an
444444
- [ ] Comprehensive tests cover all resilience behaviors
445445
- [ ] Documentation includes configuration examples and usage patterns
446446
- [ ] **Pyright type checking passes** with zero errors (run `pyright` before committing)
447+
- [ ] **Strong typing implemented** throughout all Python code
447448

448449
## Common Python-Specific Anti-Patterns to Avoid
449450

@@ -477,6 +478,12 @@ pyright file1.py file2.py module/changed_file.py
477478
- Zero Pyright errors allowed on changed files
478479
- All functions must have proper type hints
479480
- Use `typing` imports for complex types
481+
- **MANDATORY: Use strong typing throughout**:
482+
- All function parameters and return types explicitly typed
483+
- String literals use `Literal["value"]` for constants or `str` for variables
484+
- Collections use generic types: `list[str]`, `dict[str, int]`, etc.
485+
- Optional types use `Optional[T]` or `T | None`
486+
- Union types explicit: `Union[str, int]` or `str | int`
480487
- Add `# type: ignore` comments only when absolutely necessary with explanation
481488

482489
### Additional Quality Tools
@@ -506,10 +513,59 @@ echo "$CHANGED_FILES" | xargs bandit -ll
506513

507514
**Quality Standards**:
508515
- Pyright type checking: **ZERO ERRORS**
516+
- **Strong typing: MANDATORY** (all functions, parameters, returns)
509517
- Code formatting: black + isort compliance
510518
- Linting: ruff clean (no warnings)
511519
- Security: bandit clean (no high/medium severity issues)
512520

521+
### Strong Typing Examples
522+
```python
523+
from typing import Literal, Optional, Union, Any
524+
from collections.abc import Awaitable, Callable
525+
import numpy as np
526+
import pandas as pd
527+
528+
# ✅ GOOD: Strong typing examples
529+
def process_data(
530+
data: list[dict[str, Any]],
531+
mode: Literal["strict", "relaxed"],
532+
timeout: Optional[float] = None
533+
) -> dict[str, Union[int, str]]:
534+
"""Process data with strong typing."""
535+
pass
536+
537+
async def fetch_user(
538+
user_id: str,
539+
include_profile: bool = False
540+
) -> Optional[dict[str, Any]]:
541+
"""Fetch user with optional profile data."""
542+
pass
543+
544+
# ✅ GOOD: Class with strong typing
545+
class DataProcessor:
546+
def __init__(
547+
self,
548+
config: dict[str, Any],
549+
processors: list[Callable[[Any], Any]]
550+
) -> None:
551+
self.config: dict[str, Any] = config
552+
self.processors: list[Callable[[Any], Any]] = processors
553+
554+
async def process(
555+
self,
556+
items: list[dict[str, Any]]
557+
) -> list[dict[str, Any]]:
558+
"""Process items asynchronously."""
559+
pass
560+
561+
# ❌ BAD: Weak typing (avoid these patterns)
562+
def bad_function(data, mode=None): # No type hints
563+
pass
564+
565+
def poor_typing(data: Any) -> Any: # Too generic
566+
pass
567+
```
568+
513569
## Advanced Python Specialization
514570

515571
### Modern Python Idioms and Best Practices

0 commit comments

Comments
 (0)