Skip to content

Commit 0558d3f

Browse files
remove string literals around forward references using from __future import annotations
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent bc467d1 commit 0558d3f

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

src/databricks/sql/backend/databricks_client.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,18 @@
88
- Fetching metadata about catalogs, schemas, tables, and columns
99
"""
1010

11+
from __future__ import annotations
12+
1113
from abc import ABC, abstractmethod
1214
from typing import Dict, Tuple, List, Optional, Any, Union, TYPE_CHECKING
1315

1416
if TYPE_CHECKING:
1517
from databricks.sql.client import Cursor
18+
from databricks.sql.result_set import ResultSet
1619

1720
from databricks.sql.thrift_api.TCLIService import ttypes
1821
from databricks.sql.backend.types import SessionId, CommandId, CommandState
1922

20-
# Forward reference for type hints
21-
from typing import TYPE_CHECKING
22-
23-
if TYPE_CHECKING:
24-
from databricks.sql.result_set import ResultSet
25-
2623

2724
class DatabricksClient(ABC):
2825
# == Connection and Session Management ==
@@ -80,12 +77,12 @@ def execute_command(
8077
max_rows: int,
8178
max_bytes: int,
8279
lz4_compression: bool,
83-
cursor: "Cursor",
80+
cursor: Cursor,
8481
use_cloud_fetch: bool,
8582
parameters: List[ttypes.TSparkParameter],
8683
async_op: bool,
8784
enforce_embedded_schema_correctness: bool,
88-
) -> Union["ResultSet", None]:
85+
) -> Union[ResultSet, None]:
8986
"""
9087
Executes a SQL command or query within the specified session.
9188
@@ -175,8 +172,8 @@ def get_query_state(self, command_id: CommandId) -> CommandState:
175172
def get_execution_result(
176173
self,
177174
command_id: CommandId,
178-
cursor: "Cursor",
179-
) -> "ResultSet":
175+
cursor: Cursor,
176+
) -> ResultSet:
180177
"""
181178
Retrieves the results of a previously executed command.
182179
@@ -203,8 +200,8 @@ def get_catalogs(
203200
session_id: SessionId,
204201
max_rows: int,
205202
max_bytes: int,
206-
cursor: "Cursor",
207-
) -> "ResultSet":
203+
cursor: Cursor,
204+
) -> ResultSet:
208205
"""
209206
Retrieves a list of available catalogs.
210207
@@ -232,10 +229,10 @@ def get_schemas(
232229
session_id: SessionId,
233230
max_rows: int,
234231
max_bytes: int,
235-
cursor: "Cursor",
232+
cursor: Cursor,
236233
catalog_name: Optional[str] = None,
237234
schema_name: Optional[str] = None,
238-
) -> "ResultSet":
235+
) -> ResultSet:
239236
"""
240237
Retrieves a list of schemas, optionally filtered by catalog and schema name patterns.
241238
@@ -265,12 +262,12 @@ def get_tables(
265262
session_id: SessionId,
266263
max_rows: int,
267264
max_bytes: int,
268-
cursor: "Cursor",
265+
cursor: Cursor,
269266
catalog_name: Optional[str] = None,
270267
schema_name: Optional[str] = None,
271268
table_name: Optional[str] = None,
272269
table_types: Optional[List[str]] = None,
273-
) -> "ResultSet":
270+
) -> ResultSet:
274271
"""
275272
Retrieves a list of tables, optionally filtered by catalog, schema, table name, and table types.
276273
@@ -302,12 +299,12 @@ def get_columns(
302299
session_id: SessionId,
303300
max_rows: int,
304301
max_bytes: int,
305-
cursor: "Cursor",
302+
cursor: Cursor,
306303
catalog_name: Optional[str] = None,
307304
schema_name: Optional[str] = None,
308305
table_name: Optional[str] = None,
309306
column_name: Optional[str] = None,
310-
) -> "ResultSet":
307+
) -> ResultSet:
311308
"""
312309
Retrieves a list of columns, optionally filtered by catalog, schema, table, and column name patterns.
313310

src/databricks/sql/backend/filters.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
This module provides filtering capabilities for result sets returned by different backends.
55
"""
66

7+
from __future__ import annotations
8+
79
import logging
810
from typing import (
911
List,
@@ -37,8 +39,8 @@ class ResultSetFilter:
3739

3840
@staticmethod
3941
def _filter_sea_result_set(
40-
result_set: "SeaResultSet", filter_func: Callable[[List[Any]], bool]
41-
) -> "SeaResultSet":
42+
result_set: SeaResultSet, filter_func: Callable[[List[Any]], bool]
43+
) -> SeaResultSet:
4244
"""
4345
Filter a SEA result set using the provided filter function.
4446
@@ -91,11 +93,11 @@ def _filter_sea_result_set(
9193

9294
@staticmethod
9395
def filter_by_column_values(
94-
result_set: "ResultSet",
96+
result_set: ResultSet,
9597
column_index: int,
9698
allowed_values: List[str],
9799
case_sensitive: bool = False,
98-
) -> "ResultSet":
100+
) -> ResultSet:
99101
"""
100102
Filter a result set by values in a specific column.
101103
@@ -138,8 +140,8 @@ def filter_by_column_values(
138140

139141
@staticmethod
140142
def filter_tables_by_type(
141-
result_set: "ResultSet", table_types: Optional[List[str]] = None
142-
) -> "ResultSet":
143+
result_set: ResultSet, table_types: Optional[List[str]] = None
144+
) -> ResultSet:
143145
"""
144146
Filter a result set of tables by the specified table types.
145147

src/databricks/sql/backend/sea/backend.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24
import uuid
35
import time
@@ -403,12 +405,12 @@ def execute_command(
403405
max_rows: int,
404406
max_bytes: int,
405407
lz4_compression: bool,
406-
cursor: "Cursor",
408+
cursor: Cursor,
407409
use_cloud_fetch: bool,
408410
parameters: List,
409411
async_op: bool,
410412
enforce_embedded_schema_correctness: bool,
411-
) -> Union["ResultSet", None]:
413+
) -> Union[ResultSet, None]:
412414
"""
413415
Execute a SQL command using the SEA backend.
414416
@@ -592,8 +594,8 @@ def get_query_state(self, command_id: CommandId) -> CommandState:
592594
def get_execution_result(
593595
self,
594596
command_id: CommandId,
595-
cursor: "Cursor",
596-
) -> "ResultSet":
597+
cursor: Cursor,
598+
) -> ResultSet:
597599
"""
598600
Get the result of a command execution.
599601
@@ -650,8 +652,8 @@ def get_catalogs(
650652
session_id: SessionId,
651653
max_rows: int,
652654
max_bytes: int,
653-
cursor: "Cursor",
654-
) -> "ResultSet":
655+
cursor: Cursor,
656+
) -> ResultSet:
655657
"""Get available catalogs by executing 'SHOW CATALOGS'."""
656658
result = self.execute_command(
657659
operation="SHOW CATALOGS",
@@ -673,10 +675,10 @@ def get_schemas(
673675
session_id: SessionId,
674676
max_rows: int,
675677
max_bytes: int,
676-
cursor: "Cursor",
678+
cursor: Cursor,
677679
catalog_name: Optional[str] = None,
678680
schema_name: Optional[str] = None,
679-
) -> "ResultSet":
681+
) -> ResultSet:
680682
"""Get schemas by executing 'SHOW SCHEMAS IN catalog [LIKE pattern]'."""
681683
if not catalog_name:
682684
raise ValueError("Catalog name is required for get_schemas")
@@ -706,12 +708,12 @@ def get_tables(
706708
session_id: SessionId,
707709
max_rows: int,
708710
max_bytes: int,
709-
cursor: "Cursor",
711+
cursor: Cursor,
710712
catalog_name: Optional[str] = None,
711713
schema_name: Optional[str] = None,
712714
table_name: Optional[str] = None,
713715
table_types: Optional[List[str]] = None,
714-
) -> "ResultSet":
716+
) -> ResultSet:
715717
"""Get tables by executing 'SHOW TABLES IN catalog [SCHEMA LIKE pattern] [LIKE pattern]'."""
716718
if not catalog_name:
717719
raise ValueError("Catalog name is required for get_tables")
@@ -754,12 +756,12 @@ def get_columns(
754756
session_id: SessionId,
755757
max_rows: int,
756758
max_bytes: int,
757-
cursor: "Cursor",
759+
cursor: Cursor,
758760
catalog_name: Optional[str] = None,
759761
schema_name: Optional[str] = None,
760762
table_name: Optional[str] = None,
761763
column_name: Optional[str] = None,
762-
) -> "ResultSet":
764+
) -> ResultSet:
763765
"""Get columns by executing 'SHOW COLUMNS IN CATALOG catalog [SCHEMA LIKE pattern] [TABLE LIKE pattern] [LIKE pattern]'."""
764766
if not catalog_name:
765767
raise ValueError("Catalog name is required for get_columns")

src/databricks/sql/result_set.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
24
from typing import List, Optional, Any, Union, Tuple, TYPE_CHECKING
35

@@ -21,6 +23,7 @@
2123
if TYPE_CHECKING:
2224
from databricks.sql.backend.thrift_backend import ThriftDatabricksClient
2325
from databricks.sql.client import Connection
26+
2427
from databricks.sql.backend.databricks_client import DatabricksClient
2528
from databricks.sql.thrift_api.TCLIService import ttypes
2629
from databricks.sql.types import Row
@@ -40,8 +43,8 @@ class ResultSet(ABC):
4043

4144
def __init__(
4245
self,
43-
connection: "Connection",
44-
backend: "DatabricksClient",
46+
connection: Connection,
47+
backend: DatabricksClient,
4548
arraysize: int,
4649
buffer_size_bytes: int,
4750
command_id: CommandId,
@@ -193,9 +196,9 @@ class ThriftResultSet(ResultSet):
193196

194197
def __init__(
195198
self,
196-
connection: "Connection",
197-
execute_response: "ExecuteResponse",
198-
thrift_client: "ThriftDatabricksClient",
199+
connection: Connection,
200+
execute_response: ExecuteResponse,
201+
thrift_client: ThriftDatabricksClient,
199202
buffer_size_bytes: int = 104857600,
200203
arraysize: int = 10000,
201204
use_cloud_fetch: bool = True,
@@ -451,13 +454,13 @@ class SeaResultSet(ResultSet):
451454

452455
def __init__(
453456
self,
454-
connection: "Connection",
455-
execute_response: "ExecuteResponse",
456-
sea_client: "SeaDatabricksClient",
457+
connection: Connection,
458+
execute_response: ExecuteResponse,
459+
sea_client: SeaDatabricksClient,
457460
buffer_size_bytes: int = 104857600,
458461
arraysize: int = 10000,
459-
result_data: Optional["ResultData"] = None,
460-
manifest: Optional["ResultManifest"] = None,
462+
result_data: Optional[ResultData] = None,
463+
manifest: Optional[ResultManifest] = None,
461464
):
462465
"""
463466
Initialize a SeaResultSet with the response from a SEA query execution.

0 commit comments

Comments
 (0)