mirror of
https://github.com/apache/superset.git
synced 2026-04-20 16:44:46 +00:00
chore(pre-commit): Add pyupgrade and pycln hooks (#24197)
This commit is contained in:
@@ -18,7 +18,8 @@ import json
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Pattern, Set, Tuple, TYPE_CHECKING
|
||||
from re import Pattern
|
||||
from typing import Any, Optional, TYPE_CHECKING
|
||||
|
||||
from flask_babel import gettext as __
|
||||
from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION, ENUM, JSON
|
||||
@@ -73,7 +74,7 @@ COLUMN_DOES_NOT_EXIST_REGEX = re.compile(
|
||||
SYNTAX_ERROR_REGEX = re.compile('syntax error at or near "(?P<syntax_error>.*?)"')
|
||||
|
||||
|
||||
def parse_options(connect_args: Dict[str, Any]) -> Dict[str, str]:
|
||||
def parse_options(connect_args: dict[str, Any]) -> dict[str, str]:
|
||||
"""
|
||||
Parse ``options`` from ``connect_args`` into a dictionary.
|
||||
"""
|
||||
@@ -109,7 +110,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
|
||||
"P1Y": "DATE_TRUNC('year', {col})",
|
||||
}
|
||||
|
||||
custom_errors: Dict[Pattern[str], Tuple[str, SupersetErrorType, Dict[str, Any]]] = {
|
||||
custom_errors: dict[Pattern[str], tuple[str, SupersetErrorType, dict[str, Any]]] = {
|
||||
CONNECTION_INVALID_USERNAME_REGEX: (
|
||||
__('The username "%(username)s" does not exist.'),
|
||||
SupersetErrorType.CONNECTION_INVALID_USERNAME_ERROR,
|
||||
@@ -169,7 +170,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
|
||||
@classmethod
|
||||
def fetch_data(
|
||||
cls, cursor: Any, limit: Optional[int] = None
|
||||
) -> List[Tuple[Any, ...]]:
|
||||
) -> list[tuple[Any, ...]]:
|
||||
if not cursor.description:
|
||||
return []
|
||||
return super().fetch_data(cursor, limit)
|
||||
@@ -221,7 +222,7 @@ class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin):
|
||||
def get_schema_from_engine_params(
|
||||
cls,
|
||||
sqlalchemy_uri: URL,
|
||||
connect_args: Dict[str, Any],
|
||||
connect_args: dict[str, Any],
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Return the configured schema.
|
||||
@@ -253,10 +254,10 @@ class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin):
|
||||
def adjust_engine_params(
|
||||
cls,
|
||||
uri: URL,
|
||||
connect_args: Dict[str, Any],
|
||||
connect_args: dict[str, Any],
|
||||
catalog: Optional[str] = None,
|
||||
schema: Optional[str] = None,
|
||||
) -> Tuple[URL, Dict[str, Any]]:
|
||||
) -> tuple[URL, dict[str, Any]]:
|
||||
if not schema:
|
||||
return uri, connect_args
|
||||
|
||||
@@ -269,11 +270,11 @@ class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin):
|
||||
return uri, connect_args
|
||||
|
||||
@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]:
|
||||
sql = f"EXPLAIN {statement}"
|
||||
cursor.execute(sql)
|
||||
|
||||
@@ -289,8 +290,8 @@ class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin):
|
||||
|
||||
@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
|
||||
@@ -298,7 +299,7 @@ class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin):
|
||||
cls,
|
||||
database: "Database",
|
||||
inspector: Inspector,
|
||||
) -> List[str]:
|
||||
) -> list[str]:
|
||||
"""
|
||||
Return all catalogs.
|
||||
|
||||
@@ -317,7 +318,7 @@ WHERE datistemplate = false;
|
||||
@classmethod
|
||||
def get_table_names(
|
||||
cls, database: "Database", inspector: PGInspector, schema: Optional[str]
|
||||
) -> Set[str]:
|
||||
) -> set[str]:
|
||||
"""Need to consider foreign tables for PostgreSQL"""
|
||||
return set(inspector.get_table_names(schema)) | set(
|
||||
inspector.get_foreign_table_names(schema)
|
||||
@@ -325,7 +326,7 @@ WHERE datistemplate = false;
|
||||
|
||||
@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)
|
||||
|
||||
@@ -337,7 +338,7 @@ WHERE datistemplate = false;
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_extra_params(database: "Database") -> Dict[str, Any]:
|
||||
def get_extra_params(database: "Database") -> dict[str, Any]:
|
||||
"""
|
||||
For Postgres, the path to a SSL certificate is placed in `connect_args`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user