mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore(pre-commit): Add pyupgrade and pycln hooks (#24197)
This commit is contained in:
@@ -18,7 +18,8 @@ import json
|
||||
import re
|
||||
import urllib
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Pattern, Tuple, Type, TYPE_CHECKING
|
||||
from re import Pattern
|
||||
from typing import Any, Optional, TYPE_CHECKING
|
||||
|
||||
import pandas as pd
|
||||
from apispec import APISpec
|
||||
@@ -99,8 +100,8 @@ class BigQueryParametersSchema(Schema):
|
||||
|
||||
|
||||
class BigQueryParametersType(TypedDict):
|
||||
credentials_info: Dict[str, Any]
|
||||
query: Dict[str, Any]
|
||||
credentials_info: dict[str, Any]
|
||||
query: dict[str, Any]
|
||||
|
||||
|
||||
class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-methods
|
||||
@@ -173,7 +174,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
"P1Y": "{func}({col}, YEAR)",
|
||||
}
|
||||
|
||||
custom_errors: Dict[Pattern[str], Tuple[str, SupersetErrorType, Dict[str, Any]]] = {
|
||||
custom_errors: dict[Pattern[str], tuple[str, SupersetErrorType, dict[str, Any]]] = {
|
||||
CONNECTION_DATABASE_PERMISSIONS_REGEX: (
|
||||
__(
|
||||
"Unable to connect. Verify that the following roles are set "
|
||||
@@ -219,7 +220,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
|
||||
@classmethod
|
||||
def convert_dttm(
|
||||
cls, target_type: str, dttm: datetime, db_extra: Optional[Dict[str, Any]] = None
|
||||
cls, target_type: str, dttm: datetime, db_extra: Optional[dict[str, Any]] = None
|
||||
) -> Optional[str]:
|
||||
sqla_type = cls.get_sqla_column_type(target_type)
|
||||
if isinstance(sqla_type, types.Date):
|
||||
@@ -235,7 +236,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
@classmethod
|
||||
def fetch_data(
|
||||
cls, cursor: Any, limit: Optional[int] = None
|
||||
) -> List[Tuple[Any, ...]]:
|
||||
) -> list[tuple[Any, ...]]:
|
||||
data = super().fetch_data(cursor, limit)
|
||||
# Support type BigQuery Row, introduced here PR #4071
|
||||
# google.cloud.bigquery.table.Row
|
||||
@@ -280,7 +281,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
|
||||
@classmethod
|
||||
@deprecated(deprecated_in="3.0")
|
||||
def normalize_indexes(cls, indexes: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
||||
def normalize_indexes(cls, indexes: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Normalizes indexes for more consistency across db engines
|
||||
|
||||
@@ -305,7 +306,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
inspector: Inspector,
|
||||
table_name: str,
|
||||
schema: Optional[str],
|
||||
) -> List[Dict[str, Any]]:
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Get the indexes associated with the specified schema/table.
|
||||
|
||||
@@ -321,7 +322,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
@classmethod
|
||||
def extra_table_metadata(
|
||||
cls, database: "Database", table_name: str, schema_name: Optional[str]
|
||||
) -> Dict[str, Any]:
|
||||
) -> dict[str, Any]:
|
||||
indexes = database.get_indexes(table_name, schema_name)
|
||||
if not indexes:
|
||||
return {}
|
||||
@@ -354,7 +355,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
database: "Database",
|
||||
table: Table,
|
||||
df: pd.DataFrame,
|
||||
to_sql_kwargs: Dict[str, Any],
|
||||
to_sql_kwargs: dict[str, Any],
|
||||
) -> None:
|
||||
"""
|
||||
Upload data from a Pandas DataFrame to a database.
|
||||
@@ -421,7 +422,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
schema: str,
|
||||
sql: str,
|
||||
source: Optional[utils.QuerySource] = None,
|
||||
) -> List[Dict[str, Any]]:
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Estimate the cost of a multiple statement SQL query.
|
||||
|
||||
@@ -448,7 +449,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
cls,
|
||||
database: "Database",
|
||||
inspector: Inspector,
|
||||
) -> List[str]:
|
||||
) -> list[str]:
|
||||
"""
|
||||
Get all catalogs.
|
||||
|
||||
@@ -462,11 +463,11 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
return sorted(project.project_id for project in projects)
|
||||
|
||||
@classmethod
|
||||
def get_allow_cost_estimate(cls, extra: Dict[str, Any]) -> bool:
|
||||
def get_allow_cost_estimate(cls, extra: dict[str, Any]) -> bool:
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def estimate_statement_cost(cls, statement: str, cursor: Any) -> Dict[str, Any]:
|
||||
def estimate_statement_cost(cls, statement: str, cursor: Any) -> dict[str, Any]:
|
||||
with cls.get_engine(cursor) as engine:
|
||||
client = cls._get_client(engine)
|
||||
job_config = bigquery.QueryJobConfig(dry_run=True)
|
||||
@@ -503,15 +504,15 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
|
||||
@classmethod
|
||||
def query_cost_formatter(
|
||||
cls, raw_cost: List[Dict[str, Any]]
|
||||
) -> List[Dict[str, str]]:
|
||||
cls, raw_cost: list[dict[str, Any]]
|
||||
) -> list[dict[str, str]]:
|
||||
return [{k: str(v) for k, v in row.items()} for row in raw_cost]
|
||||
|
||||
@classmethod
|
||||
def build_sqlalchemy_uri(
|
||||
cls,
|
||||
parameters: BigQueryParametersType,
|
||||
encrypted_extra: Optional[Dict[str, Any]] = None,
|
||||
encrypted_extra: Optional[dict[str, Any]] = None,
|
||||
) -> str:
|
||||
query = parameters.get("query", {})
|
||||
query_params = urllib.parse.urlencode(query)
|
||||
@@ -533,7 +534,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
def get_parameters_from_uri(
|
||||
cls,
|
||||
uri: str,
|
||||
encrypted_extra: Optional[Dict[str, Any]] = None,
|
||||
encrypted_extra: Optional[dict[str, Any]] = None,
|
||||
) -> Any:
|
||||
value = make_url_safe(uri)
|
||||
|
||||
@@ -592,7 +593,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
return json.dumps(new_config)
|
||||
|
||||
@classmethod
|
||||
def get_dbapi_exception_mapping(cls) -> Dict[Type[Exception], Type[Exception]]:
|
||||
def get_dbapi_exception_mapping(cls) -> dict[type[Exception], type[Exception]]:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from google.auth.exceptions import DefaultCredentialsError
|
||||
|
||||
@@ -602,7 +603,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
def validate_parameters(
|
||||
cls,
|
||||
properties: BasicPropertiesType, # pylint: disable=unused-argument
|
||||
) -> List[SupersetError]:
|
||||
) -> list[SupersetError]:
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
@@ -636,7 +637,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
show_cols: bool = False,
|
||||
indent: bool = True,
|
||||
latest_partition: bool = True,
|
||||
cols: Optional[List[Dict[str, Any]]] = None,
|
||||
cols: Optional[list[dict[str, Any]]] = None,
|
||||
) -> str:
|
||||
"""
|
||||
Remove array structures from `SELECT *`.
|
||||
@@ -699,7 +700,7 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _get_fields(cls, cols: List[Dict[str, Any]]) -> List[Any]:
|
||||
def _get_fields(cls, cols: list[dict[str, Any]]) -> list[Any]:
|
||||
"""
|
||||
Label columns using their fully qualified name.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user