---
issue: 133
title: Python Bot Type Hints (Screenshare Bot)
analyzed: 2025-10-13T18:53:14Z
estimated_hours: 4
parallelization_factor: 3.5
---

# Parallel Work Analysis: Issue #133

## Overview

Add complete type hints to the screenshare bot Python codebase (7 modules + tests), configure mypy for type checking, and ensure 100% type coverage. This is a clean parallelization opportunity since each module can be typed independently with minimal overlap.

## Parallel Streams

### Stream A: Core Bot Module + Environment Setup
**Scope**: Setup environment and type the main bot orchestration module
**Files**:
- `apps/slide-system/bots/screenshare-bot/pyproject.toml` (create)
- `apps/slide-system/bots/screenshare-bot/bot.py` (main orchestration)
**Agent Type**: general-purpose
**Can Start**: immediately
**Estimated Hours**: 1.5h
**Dependencies**: none

**Rationale**: Bot.py is the main entry point and orchestrates all other modules. Typing this first establishes the interfaces that other modules must conform to. Environment setup (pyproject.toml, mypy config) is a prerequisite for validation.

### Stream B: Screenshot & Frame Processing Modules
**Scope**: Type the browser automation and frame processing pipeline
**Files**:
- `apps/slide-system/bots/screenshare-bot/screenshot_capture.py`
- `apps/slide-system/bots/screenshare-bot/frame_processor.py`
**Agent Type**: general-purpose
**Can Start**: immediately
**Estimated Hours**: 1h
**Dependencies**: none

**Rationale**: These modules are standalone with minimal dependencies. screenshot_capture uses Playwright types (already typed), frame_processor is pure PIL/bytes manipulation.

### Stream C: Slide Control Modules
**Scope**: Type the Supabase real-time and navigation modules
**Files**:
- `apps/slide-system/bots/screenshare-bot/slide_control_listener.py`
- `apps/slide-system/bots/screenshare-bot/slide_navigator.py`
**Agent Type**: general-purpose
**Can Start**: immediately
**Estimated Hours**: 1h
**Dependencies**: none

**Rationale**: These modules interact but have clear interfaces. slide_control_listener uses supabase-py types, slide_navigator uses Playwright types.

### Stream D: Support Modules & Validation
**Scope**: Type lifecycle manager, URL validator, and run final mypy validation
**Files**:
- `apps/slide-system/bots/screenshare-bot/lifecycle_manager.py`
- `apps/slide-system/bots/screenshare-bot/deck_url_validator.py`
- `apps/slide-system/bots/screenshare-bot/performance_monitor.py` (if exists)
**Agent Type**: general-purpose
**Can Start**: after Stream A completes
**Estimated Hours**: 0.5h
**Dependencies**: Stream A (needs bot.py types for lifecycle_manager)

**Rationale**: lifecycle_manager depends on the ScreenshareBot type from bot.py. Other modules are standalone. This stream also runs final mypy validation across all modules.

## Coordination Points

### Shared Files
Minimal overlap:
- `.gitignore` - Stream A adds `.venv/` (one-time, low conflict risk)
- `pyproject.toml` - Stream A creates this file

### Sequential Requirements
1. Stream A must complete before Stream D (lifecycle_manager needs ScreenshareBot type)
2. All streams must complete before final mypy validation in Stream D
3. Test modules can be typed in any stream alongside their corresponding module

### Type Import Patterns
Common imports all streams will use:
```python
from typing import Dict, Optional, Any, List, Callable, Tuple
from typing import TypeVar, Generic, Awaitable, Coroutine
```

## Conflict Risk Assessment

- **Low Risk**: Each stream works on different files
- **No shared core files** being modified simultaneously
- **Clear module boundaries** prevent interface conflicts
- **Well-typed dependencies** (Playwright, supabase-py, Pipecat, aiohttp, PIL)

## Parallelization Strategy

**Recommended Approach**: hybrid

**Execution Plan**:
1. Launch Streams A, B, C simultaneously (3 parallel agents)
2. Start Stream D when A completes
3. Stream D performs final validation and testing

**Why hybrid?**
- Streams A, B, C are fully independent
- Stream D depends on A for ScreenshareBot type
- Maximizes parallelization while respecting dependencies

## Expected Timeline

**With parallel execution**:
- Wall time: 1.5h (max of Stream A) + 0.5h (Stream D) = **2h total**
- Total work: 4h
- Efficiency gain: **50% faster** than sequential

**Without parallel execution**:
- Wall time: 1.5h + 1h + 1h + 0.5h = **4h total**

**Parallelization factor**: 2x speedup

## Type Hint Patterns

### Module-level Type Definitions
Each stream should follow these patterns:

**Async functions:**
```python
async def start(self) -> None:
    """Start the listener."""
    ...

async def fetch_data(url: str) -> Dict[str, Any]:
    """Fetch data from URL."""
    ...
```

**Callbacks:**
```python
from typing import Callable, Awaitable

CallbackType = Callable[[str, Optional[int]], Awaitable[None]]

def __init__(self, on_command: CallbackType):
    self.on_command = on_command
```

**Generic types:**
```python
from typing import TypeVar, Generic

T = TypeVar('T')

async def retry_with_backoff(
    func: Callable[[], Coroutine[Any, Any, T]],
    max_attempts: int = 3
) -> T:
    ...
```

**Class attributes:**
```python
class ScreenshotCapture:
    def __init__(self, deck_url: str):
        self.deck_url: str = deck_url
        self._page: Optional[Page] = None
        self._capture_count: int = 0
```

## Mypy Configuration

Stream A will create `pyproject.toml`:

```toml
[tool.mypy]
python_version = "3.11"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
ignore_missing_imports = false
show_error_codes = true
strict_optional = true
check_untyped_defs = true

# Per-module overrides if needed
[[tool.mypy.overrides]]
module = "pipecat.*"
ignore_missing_imports = true
```

## Testing Strategy

Each stream should:
1. Add type hints to all functions
2. Run `mypy <file>.py` locally to check for errors
3. Fix any type errors iteratively
4. Ensure existing functionality is unchanged

Stream D performs final validation:
```bash
cd apps/slide-system/bots/screenshare-bot
source .venv/bin/activate
mypy bot.py screenshot_capture.py slide_control_listener.py \
     slide_navigator.py lifecycle_manager.py deck_url_validator.py \
     frame_processor.py
```

Expected output: `Success: no issues found in 7 source files`

## Notes

- **Dependencies are well-typed**: Playwright, supabase-py, Pipecat, and aiohttp already have type stubs
- **Test files**: Can be typed opportunistically within each stream (e.g., Stream B types test_screenshot_capture.py)
- **Performance**: Type hints have zero runtime cost in Python
- **Backwards compatibility**: Type hints are optional in Python - adding them doesn't break existing code
- **Documentation benefit**: Type hints serve as inline documentation for function signatures
