|
| 1 | +# Python 3.8 Compatibility Fix Plan |
| 2 | + |
| 3 | +## Branch |
| 4 | +`fix/python-38-compatibility` |
| 5 | + |
| 6 | +## Problem Summary |
| 7 | + |
| 8 | +**Root Cause:** The codebase uses Python 3.9+ type annotation syntax (`dict[...]`, `list[...]`) which is incompatible with Python 3.8. This syntax was introduced in [PEP 585](https://peps.python.org/pep-0585/) and is only available in Python 3.9+. |
| 9 | + |
| 10 | +**Why It Wasn't Caught Earlier:** |
| 11 | +- The bug was present since the initial commit (43fd07b) |
| 12 | +- Tests passed on Python 3.8 until Nov 9, 2025 |
| 13 | +- The failure was triggered by upgrading `actions/setup-python` from v5 to v6 (PR #15) |
| 14 | +- The new version installs a stricter Python 3.8 build that properly enforces PEP 585 restrictions |
| 15 | + |
| 16 | +**Impact:** |
| 17 | +- ❌ Python 3.8 tests fail with `TypeError: 'type' object is not subscriptable` |
| 18 | +- ✅ Python 3.9+ tests pass (syntax is valid) |
| 19 | +- Project claims Python 3.8+ support but doesn't deliver it |
| 20 | + |
| 21 | +## Affected Files |
| 22 | + |
| 23 | +Found **3 occurrences** of Python 3.9+ syntax: |
| 24 | + |
| 25 | +1. **`src/toon_format/constants.py:48`** |
| 26 | + ```python |
| 27 | + DELIMITERS: dict[str, "Delimiter"] = { |
| 28 | + ``` |
| 29 | + |
| 30 | +2. **`src/toon_format/utils.py:94`** |
| 31 | + ```python |
| 32 | + def estimate_savings(data: Any, encoding: str = "o200k_base") -> dict[str, Any]: |
| 33 | + ``` |
| 34 | + |
| 35 | +3. **`src/toon_format/writer.py:27`** |
| 36 | + ```python |
| 37 | + self._indent_cache: dict[int, str] = {0: ""} |
| 38 | + ``` |
| 39 | + |
| 40 | +## Solution |
| 41 | + |
| 42 | +Replace Python 3.9+ syntax with Python 3.8-compatible `typing` module imports: |
| 43 | + |
| 44 | +| Python 3.9+ | Python 3.8 Compatible | |
| 45 | +|-------------|----------------------| |
| 46 | +| `dict[K, V]` | `Dict[K, V]` (from `typing`) | |
| 47 | +| `list[T]` | `List[T]` (from `typing`) | |
| 48 | +| `set[T]` | `Set[T]` (from `typing`) | |
| 49 | +| `tuple[T, ...]` | `Tuple[T, ...]` (from `typing`) | |
| 50 | + |
| 51 | +## Implementation Steps |
| 52 | + |
| 53 | +### 1. Fix `src/toon_format/constants.py` |
| 54 | +- [x] Identified issue at line 48 |
| 55 | +- [ ] Add `from typing import Dict` to imports |
| 56 | +- [ ] Replace `dict[str, "Delimiter"]` with `Dict[str, "Delimiter"]` |
| 57 | + |
| 58 | +### 2. Fix `src/toon_format/utils.py` |
| 59 | +- [x] Identified issue at line 94 |
| 60 | +- [ ] Add `from typing import Dict` to imports (if not already present) |
| 61 | +- [ ] Replace `dict[str, Any]` with `Dict[str, Any]` |
| 62 | + |
| 63 | +### 3. Fix `src/toon_format/writer.py` |
| 64 | +- [x] Identified issue at line 27 |
| 65 | +- [ ] Add `from typing import Dict` to imports (if not already present) |
| 66 | +- [ ] Replace `dict[int, str]` with `Dict[int, str]` |
| 67 | + |
| 68 | +### 4. Update mypy Configuration (Optional but Recommended) |
| 69 | +- [ ] Change `python_version = "3.9"` to `python_version = "3.8"` in `pyproject.toml` |
| 70 | +- **Rationale:** This ensures mypy catches Python 3.8 incompatibilities during development |
| 71 | + |
| 72 | +### 5. Testing & Validation |
| 73 | +- [ ] Run tests on Python 3.8: `uv run pytest` (with Python 3.8 active) |
| 74 | +- [ ] Run tests on Python 3.9: Ensure backward compatibility |
| 75 | +- [ ] Run tests on Python 3.10: Ensure backward compatibility |
| 76 | +- [ ] Run tests on Python 3.11: Ensure backward compatibility |
| 77 | +- [ ] Run tests on Python 3.12: Ensure backward compatibility |
| 78 | +- [ ] Run mypy: `uv run mypy src/toon_format` |
| 79 | +- [ ] Run ruff check: `uv run ruff check src/toon_format tests` |
| 80 | +- [ ] Run ruff format: `uv run ruff format src/toon_format tests` |
| 81 | + |
| 82 | +### 6. Commit & PR |
| 83 | +- [ ] Commit changes with message: `fix: replace Python 3.9+ type syntax with Python 3.8-compatible typing imports` |
| 84 | +- [ ] Push branch: `git push origin fix/python-38-compatibility` |
| 85 | +- [ ] Create PR with detailed description linking to this plan |
| 86 | + |
| 87 | +## Expected Changes Summary |
| 88 | + |
| 89 | +**Files Modified:** 3 |
| 90 | +- `src/toon_format/constants.py` |
| 91 | +- `src/toon_format/utils.py` |
| 92 | +- `src/toon_format/writer.py` |
| 93 | + |
| 94 | +**Lines Changed:** ~6 lines (3 type annotations + 3 import additions) |
| 95 | + |
| 96 | +**Breaking Changes:** None (backward compatible with Python 3.9+) |
| 97 | + |
| 98 | +## Verification Checklist |
| 99 | + |
| 100 | +After implementation, verify: |
| 101 | +- [x] Branch created: `fix/python-38-compatibility` |
| 102 | +- [ ] All 3 files fixed |
| 103 | +- [ ] All imports added correctly |
| 104 | +- [ ] Python 3.8 tests pass |
| 105 | +- [ ] Python 3.9-3.12 tests pass |
| 106 | +- [ ] mypy passes |
| 107 | +- [ ] ruff check passes |
| 108 | +- [ ] ruff format passes |
| 109 | +- [ ] No new issues introduced |
| 110 | +- [ ] PR created with proper description |
| 111 | + |
| 112 | +## Additional Notes |
| 113 | + |
| 114 | +**Why This Matters:** |
| 115 | +- The project explicitly supports Python 3.8+ in `pyproject.toml` (`requires-python = ">=3.8"`) |
| 116 | +- Many production environments still use Python 3.8 (EOL: October 2024, but widely deployed) |
| 117 | +- This is a **critical bug** that prevents installation/usage on Python 3.8 |
| 118 | + |
| 119 | +**Future Prevention:** |
| 120 | +- Set `mypy python_version = "3.8"` to catch these issues during development |
| 121 | +- Consider adding a pre-commit hook that runs mypy with Python 3.8 target |
| 122 | +- CI already tests Python 3.8, but the bug slipped through due to environmental changes |
| 123 | + |
| 124 | +## References |
| 125 | + |
| 126 | +- [PEP 585 - Type Hinting Generics In Standard Collections](https://peps.python.org/pep-0585/) |
| 127 | +- [Python 3.8 Release Notes](https://docs.python.org/3/whatsnew/3.8.html) |
| 128 | +- [typing module documentation](https://docs.python.org/3/library/typing.html) |
| 129 | + |
0 commit comments