44
55import datetime
66from collections import Counter
7- from typing import Any , cast
7+ from typing import TYPE_CHECKING , Any
88
99from excel_dbapi .engines .base import TableData
1010
11+ if TYPE_CHECKING :
12+ from excel_dbapi .connection import ExcelConnection
13+
1114METADATA_SHEET = "__excel_meta__"
1215
1316
14- def list_tables (connection : Any , include_meta : bool = False ) -> list [str ]:
17+ def list_tables (connection : ExcelConnection , include_meta : bool = False ) -> list [str ]:
1518 """Return worksheet names, excluding metadata sheet by default."""
16- sheets = cast ( list [str ], connection .engine .list_sheets () )
19+ sheets : list [str ] = connection .engine .list_sheets ()
1720 if not include_meta :
1821 sheets = [sheet for sheet in sheets if sheet != METADATA_SHEET ]
1922 return sheets
2023
2124
22- def has_table (connection : Any , table_name : str ) -> bool :
25+ def has_table (connection : ExcelConnection , table_name : str ) -> bool :
2326 """Check if a worksheet exists (case-insensitive)."""
2427 return _resolve_sheet_name (connection , table_name ) is not None
2528
2629
27- def _resolve_sheet_name (connection : Any , table_name : str ) -> str | None :
28- for sheet_name in cast ( list [ str ], connection .engine .list_sheets () ):
30+ def _resolve_sheet_name (connection : ExcelConnection , table_name : str ) -> str | None :
31+ for sheet_name in connection .engine .list_sheets ():
2932 if sheet_name .lower () == table_name .lower ():
3033 return sheet_name
3134 return None
3235
3336
3437def get_columns (
35- connection : Any , table_name : str , sample_size : int | None = 100
38+ connection : ExcelConnection , table_name : str , sample_size : int | None = 100
3639) -> list [dict [str , Any ]]:
3740 """Return column metadata by sampling data rows."""
3841 resolved_table_name = _resolve_sheet_name (connection , table_name )
@@ -98,7 +101,7 @@ def _classify_value_type(value: Any) -> str:
98101
99102
100103def write_table_metadata (
101- connection : Any , table_name : str , columns : list [dict [str , Any ]]
104+ connection : ExcelConnection , table_name : str , columns : list [dict [str , Any ]]
102105) -> None :
103106 """Write column metadata to the hidden metadata sheet."""
104107 engine = connection .engine
@@ -150,7 +153,7 @@ def write_table_metadata(
150153
151154
152155def read_table_metadata (
153- connection : Any , table_name : str
156+ connection : ExcelConnection , table_name : str
154157) -> list [dict [str , Any ]] | None :
155158 """Read column metadata from the metadata sheet."""
156159 sheets = connection .engine .list_sheets ()
@@ -175,7 +178,7 @@ def read_table_metadata(
175178 ]
176179
177180
178- def remove_table_metadata (connection : Any , table_name : str ) -> None :
181+ def remove_table_metadata (connection : ExcelConnection , table_name : str ) -> None :
179182 """Remove metadata for a table from the metadata sheet."""
180183 sheets = connection .engine .list_sheets ()
181184 if METADATA_SHEET not in sheets :
0 commit comments