Skip to content

Commit 5f1ff9c

Browse files
authored
fix: Python 3.8 compatibility - replace PEP 585 type syntax with typing module imports (#24)
* fix: replace Python 3.9+ type syntax with Python 3.8-compatible typing imports - Replace dict[K, V] with Dict[K, V] from typing module - Replace list[T] with List[T] from typing module - Fixes Python 3.8 compatibility broken by actions/setup-python v6 upgrade - Affected files: constants.py, utils.py, writer.py - All tests pass on Python 3.8, 3.9, and 3.12 - Resolves TypeError: 'type' object is not subscriptable on Python 3.8 The codebase used Python 3.9+ PEP 585 syntax (dict[...], list[...]) which is incompatible with Python 3.8. This was exposed when GitHub Actions upgraded actions/setup-python from v5 to v6, which installs a stricter Python 3.8 build that properly enforces type annotation restrictions. This fix ensures the project delivers on its Python 3.8+ support claim in pyproject.toml (requires-python = '>=3.8'). * chore: remove FIX_PLAN.md - no longer needed
1 parent d1ed0e9 commit 5f1ff9c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/toon_format/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
the TOON implementation. Centralizes magic values for maintainability.
77
"""
88

9-
from typing import TYPE_CHECKING
9+
from typing import TYPE_CHECKING, Dict
1010

1111
if TYPE_CHECKING:
1212
from .types import Delimiter
@@ -45,7 +45,7 @@
4545
# endregion
4646

4747
# region Delimiters
48-
DELIMITERS: dict[str, "Delimiter"] = {
48+
DELIMITERS: Dict[str, "Delimiter"] = {
4949
"comma": COMMA,
5050
"tab": TAB,
5151
"pipe": PIPE,

src/toon_format/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import functools
2727
import json
28-
from typing import Any
28+
from typing import Any, Dict
2929

3030
# Import encode from parent package (defined in __init__.py before this module is imported)
3131
# __init__.py defines encode() before importing utils, so this is safe
@@ -91,7 +91,7 @@ def count_tokens(text: str, encoding: str = "o200k_base") -> int:
9191
return len(enc.encode(text))
9292

9393

94-
def estimate_savings(data: Any, encoding: str = "o200k_base") -> dict[str, Any]:
94+
def estimate_savings(data: Any, encoding: str = "o200k_base") -> Dict[str, Any]:
9595
"""Compare token counts between JSON and TOON formats.
9696
9797
Args:

src/toon_format/writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
indent string caching for performance.
77
"""
88

9-
from typing import List
9+
from typing import Dict, List
1010

1111
from .types import Depth
1212

@@ -24,7 +24,7 @@ def __init__(self, indent_size: int) -> None:
2424
# Ensure nested structures remain distinguishable even for indent=0
2525
normalized_indent = indent_size if indent_size > 0 else 1
2626
self._indentation_string = " " * normalized_indent
27-
self._indent_cache: dict[int, str] = {0: ""}
27+
self._indent_cache: Dict[int, str] = {0: ""}
2828
self._indent_size = indent_size
2929

3030
def push(self, depth: Depth, content: str) -> None:

0 commit comments

Comments
 (0)