[Enhancement] Support type hints and dataclass compatibility for Python under 3.10 (#63131)
Why I'm doing: starrocks-python-client support most of the python3 version, but there are some new features that is not compatibility for Python under 3.10 What I'm doing: use Union for supporting type hints in python under 3.10 not setting kw_only for dataclasses in python under 3.10
This commit is contained in:
parent
0682fbf3a7
commit
1859c8263c
|
|
@ -15,6 +15,7 @@
|
|||
import re
|
||||
from textwrap import dedent
|
||||
import time
|
||||
from typing import Union
|
||||
|
||||
from sqlalchemy import Connection, exc, schema as sa_schema
|
||||
from sqlalchemy.dialects.mysql.pymysql import MySQLDialect_pymysql
|
||||
|
|
@ -423,7 +424,7 @@ class StarRocksDialect(MySQLDialect_pymysql):
|
|||
return _reflection.StarRocksTableDefinitionParser(self, preparer)
|
||||
|
||||
def _read_from_information_schema(
|
||||
self, connection: Connection, inf_sch_table: str, charset: str | None = None, **kwargs
|
||||
self, connection: Connection, inf_sch_table: str, charset: Union[str, None] = None, **kwargs
|
||||
):
|
||||
def escape_single_quote(s):
|
||||
return s.replace("'", "\\'")
|
||||
|
|
@ -449,7 +450,7 @@ class StarRocksDialect(MySQLDialect_pymysql):
|
|||
return rows
|
||||
|
||||
@reflection.cache
|
||||
def _setup_parser(self, connection: Connection, table_name: str, schema: str | None = None, **kw):
|
||||
def _setup_parser(self, connection: Connection, table_name: str, schema: Union[str, None] = None, **kw):
|
||||
charset = self._connection_charset
|
||||
parser = self._tabledef_parser
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
import dataclasses
|
||||
import json
|
||||
import re
|
||||
from typing import Any
|
||||
from typing import Any, Union
|
||||
|
||||
from sqlalchemy.dialects.mysql.types import DATETIME
|
||||
from sqlalchemy.dialects.mysql.types import TIME
|
||||
|
|
@ -27,12 +27,13 @@ from sqlalchemy import log
|
|||
from sqlalchemy import types as sqltypes
|
||||
from sqlalchemy import util
|
||||
|
||||
|
||||
@dataclasses.dataclass(kw_only=True)
|
||||
# kw_only is added in python 3.10
|
||||
# https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass
|
||||
@dataclasses.dataclass(**dict(kw_only=True) if 'KW_ONLY' in dataclasses.__all__ else {})
|
||||
class ReflectedState(object):
|
||||
"""Stores informations about table or view."""
|
||||
|
||||
table_name: str | None = None
|
||||
table_name: Union[str, None] = None
|
||||
columns: list[dict] = dataclasses.field(default_factory=list)
|
||||
table_options: dict[str, str] = dataclasses.field(default_factory=dict)
|
||||
keys: list[dict] = dataclasses.field(default_factory=list)
|
||||
|
|
|
|||
Loading…
Reference in New Issue