Skip to content

Commit c434b11

Browse files
committed
type: add types.py with type aliases for md2zhihu
Define common type aliases to be used across the codebase for consistent type annotations. Changes: - Add `ASTNode` and `ASTNodes` type aliases for AST nodes - Add `RefDict` type alias for reference dictionaries - Add `FeatureHandler` and `Features` type aliases for renderer features - Add `typing_extensions` dependency for Python 3.9 compatibility
1 parent 064bb13 commit c434b11

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

md2zhihu/types.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Type definitions for md2zhihu"""
2+
3+
from __future__ import annotations
4+
5+
from typing import Any
6+
from typing import Callable
7+
from typing import Dict
8+
from typing import List
9+
from typing import Optional
10+
from typing import Union
11+
12+
from typing_extensions import TypeAlias
13+
14+
# AST node types
15+
ASTNode: TypeAlias = Dict[str, Any]
16+
ASTNodes: TypeAlias = List[ASTNode]
17+
18+
# Reference dictionary: {ref_id: url}
19+
RefDict: TypeAlias = Dict[str, str]
20+
21+
# Feature handler type for MDRender
22+
# Returns list of rendered lines, or None if not handled
23+
FeatureHandler: TypeAlias = Callable[..., Optional[List[str]]]
24+
25+
# Features dictionary: {node_type: handler} or {node_type: {subtype: handler}}
26+
Features: TypeAlias = Dict[str, Union[FeatureHandler, Dict[str, FeatureHandler]]]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies = [
3131
"k3fs>=0.1.5,<0.2",
3232
"k3git>=0.1.18,<0.2",
3333
"k3handy>=0.1.12,<0.2",
34+
"typing_extensions>=4.0,<5",
3435
"urllib3>=1.26.7,<3",
3536
]
3637

0 commit comments

Comments
 (0)