mirror of
https://github.com/apache/superset.git
synced 2026-08-12 11:11:01 +00:00
chore(pre-commit): Add pyupgrade and pycln hooks (#24197)
This commit is contained in:
+30
-27
@@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
# pylint: disable=line-too-long
|
||||
"""A collection of ORM sqlalchemy models for Superset"""
|
||||
import builtins
|
||||
import enum
|
||||
import json
|
||||
import logging
|
||||
@@ -25,7 +26,7 @@ from contextlib import closing, contextmanager, nullcontext
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
from functools import lru_cache
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, TYPE_CHECKING
|
||||
from typing import Any, Callable, Optional, TYPE_CHECKING
|
||||
|
||||
import numpy
|
||||
import pandas as pd
|
||||
@@ -194,7 +195,7 @@ class Database(
|
||||
return self.db_engine_spec.allows_subqueries
|
||||
|
||||
@property
|
||||
def function_names(self) -> List[str]:
|
||||
def function_names(self) -> list[str]:
|
||||
try:
|
||||
return self.db_engine_spec.get_function_names(self)
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
@@ -234,7 +235,7 @@ class Database(
|
||||
return True
|
||||
|
||||
@property
|
||||
def data(self) -> Dict[str, Any]:
|
||||
def data(self) -> dict[str, Any]:
|
||||
return {
|
||||
"id": self.id,
|
||||
"name": self.database_name,
|
||||
@@ -271,7 +272,7 @@ class Database(
|
||||
return self.db_engine_spec.mask_encrypted_extra(self.encrypted_extra)
|
||||
|
||||
@property
|
||||
def parameters(self) -> Dict[str, Any]:
|
||||
def parameters(self) -> dict[str, Any]:
|
||||
# Database parameters are a dictionary of values that are used to make up
|
||||
# the sqlalchemy_uri
|
||||
# When returning the parameters we should use the masked SQLAlchemy URI and the
|
||||
@@ -296,7 +297,7 @@ class Database(
|
||||
return parameters
|
||||
|
||||
@property
|
||||
def parameters_schema(self) -> Dict[str, Any]:
|
||||
def parameters_schema(self) -> dict[str, Any]:
|
||||
try:
|
||||
parameters_schema = self.db_engine_spec.parameters_json_schema() # type: ignore
|
||||
except Exception: # pylint: disable=broad-except
|
||||
@@ -304,7 +305,7 @@ class Database(
|
||||
return parameters_schema
|
||||
|
||||
@property
|
||||
def metadata_cache_timeout(self) -> Dict[str, Any]:
|
||||
def metadata_cache_timeout(self) -> dict[str, Any]:
|
||||
return self.get_extra().get("metadata_cache_timeout", {})
|
||||
|
||||
@property
|
||||
@@ -324,15 +325,15 @@ class Database(
|
||||
return self.metadata_cache_timeout.get("table_cache_timeout")
|
||||
|
||||
@property
|
||||
def default_schemas(self) -> List[str]:
|
||||
def default_schemas(self) -> list[str]:
|
||||
return self.get_extra().get("default_schemas", [])
|
||||
|
||||
@property
|
||||
def connect_args(self) -> Dict[str, Any]:
|
||||
def connect_args(self) -> dict[str, Any]:
|
||||
return self.get_extra().get("engine_params", {}).get("connect_args", {})
|
||||
|
||||
@property
|
||||
def engine_information(self) -> Dict[str, Any]:
|
||||
def engine_information(self) -> dict[str, Any]:
|
||||
try:
|
||||
engine_information = self.db_engine_spec.get_public_information()
|
||||
except Exception: # pylint: disable=broad-except
|
||||
@@ -540,7 +541,7 @@ class Database(
|
||||
"""Add quotes to potential identifiter expressions if needed"""
|
||||
return self.get_dialect().identifier_preparer.quote
|
||||
|
||||
def get_reserved_words(self) -> Set[str]:
|
||||
def get_reserved_words(self) -> set[str]:
|
||||
return self.get_dialect().preparer.reserved_words
|
||||
|
||||
def get_df( # pylint: disable=too-many-locals
|
||||
@@ -629,7 +630,7 @@ class Database(
|
||||
show_cols: bool = False,
|
||||
indent: bool = True,
|
||||
latest_partition: bool = False,
|
||||
cols: Optional[List[Dict[str, Any]]] = None,
|
||||
cols: Optional[list[dict[str, Any]]] = None,
|
||||
) -> str:
|
||||
"""Generates a ``select *`` statement in the proper dialect"""
|
||||
eng = self._get_sqla_engine(schema=schema, source=utils.QuerySource.SQL_LAB)
|
||||
@@ -670,7 +671,7 @@ class Database(
|
||||
cache: bool = False,
|
||||
cache_timeout: Optional[int] = None,
|
||||
force: bool = False,
|
||||
) -> Set[Tuple[str, str]]:
|
||||
) -> set[tuple[str, str]]:
|
||||
"""Parameters need to be passed as keyword arguments.
|
||||
|
||||
For unused parameters, they are referenced in
|
||||
@@ -706,7 +707,7 @@ class Database(
|
||||
cache: bool = False,
|
||||
cache_timeout: Optional[int] = None,
|
||||
force: bool = False,
|
||||
) -> Set[Tuple[str, str]]:
|
||||
) -> set[tuple[str, str]]:
|
||||
"""Parameters need to be passed as keyword arguments.
|
||||
|
||||
For unused parameters, they are referenced in
|
||||
@@ -750,7 +751,7 @@ class Database(
|
||||
cache_timeout: Optional[int] = None,
|
||||
force: bool = False,
|
||||
ssh_tunnel: Optional["SSHTunnel"] = None,
|
||||
) -> List[str]:
|
||||
) -> list[str]:
|
||||
"""Parameters need to be passed as keyword arguments.
|
||||
|
||||
For unused parameters, they are referenced in
|
||||
@@ -768,13 +769,15 @@ class Database(
|
||||
raise self.db_engine_spec.get_dbapi_mapped_exception(ex) from ex
|
||||
|
||||
@property
|
||||
def db_engine_spec(self) -> Type[db_engine_specs.BaseEngineSpec]:
|
||||
def db_engine_spec(self) -> builtins.type[db_engine_specs.BaseEngineSpec]:
|
||||
url = make_url_safe(self.sqlalchemy_uri_decrypted)
|
||||
return self.get_db_engine_spec(url)
|
||||
|
||||
@classmethod
|
||||
@lru_cache(maxsize=LRU_CACHE_MAX_SIZE)
|
||||
def get_db_engine_spec(cls, url: URL) -> Type[db_engine_specs.BaseEngineSpec]:
|
||||
def get_db_engine_spec(
|
||||
cls, url: URL
|
||||
) -> builtins.type[db_engine_specs.BaseEngineSpec]:
|
||||
backend = url.get_backend_name()
|
||||
try:
|
||||
driver = url.get_driver_name()
|
||||
@@ -784,7 +787,7 @@ class Database(
|
||||
|
||||
return db_engine_specs.get_engine_spec(backend, driver)
|
||||
|
||||
def grains(self) -> Tuple[TimeGrain, ...]:
|
||||
def grains(self) -> tuple[TimeGrain, ...]:
|
||||
"""Defines time granularity database-specific expressions.
|
||||
|
||||
The idea here is to make it easy for users to change the time grain
|
||||
@@ -795,10 +798,10 @@ class Database(
|
||||
"""
|
||||
return self.db_engine_spec.get_time_grains()
|
||||
|
||||
def get_extra(self) -> Dict[str, Any]:
|
||||
def get_extra(self) -> dict[str, Any]:
|
||||
return self.db_engine_spec.get_extra_params(self)
|
||||
|
||||
def get_encrypted_extra(self) -> Dict[str, Any]:
|
||||
def get_encrypted_extra(self) -> dict[str, Any]:
|
||||
encrypted_extra = {}
|
||||
if self.encrypted_extra:
|
||||
try:
|
||||
@@ -809,7 +812,7 @@ class Database(
|
||||
return encrypted_extra
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def update_params_from_encrypted_extra(self, params: Dict[str, Any]) -> None:
|
||||
def update_params_from_encrypted_extra(self, params: dict[str, Any]) -> None:
|
||||
self.db_engine_spec.update_params_from_encrypted_extra(self, params)
|
||||
|
||||
def get_table(self, table_name: str, schema: Optional[str] = None) -> Table:
|
||||
@@ -832,7 +835,7 @@ class Database(
|
||||
|
||||
def get_columns(
|
||||
self, table_name: str, schema: Optional[str] = None
|
||||
) -> List[Dict[str, Any]]:
|
||||
) -> list[dict[str, Any]]:
|
||||
with self.get_inspector_with_context() as inspector:
|
||||
return self.db_engine_spec.get_columns(inspector, table_name, schema)
|
||||
|
||||
@@ -840,19 +843,19 @@ class Database(
|
||||
self,
|
||||
table_name: str,
|
||||
schema: Optional[str] = None,
|
||||
) -> List[MetricType]:
|
||||
) -> list[MetricType]:
|
||||
with self.get_inspector_with_context() as inspector:
|
||||
return self.db_engine_spec.get_metrics(self, inspector, table_name, schema)
|
||||
|
||||
def get_indexes(
|
||||
self, table_name: str, schema: Optional[str] = None
|
||||
) -> List[Dict[str, Any]]:
|
||||
) -> list[dict[str, Any]]:
|
||||
with self.get_inspector_with_context() as inspector:
|
||||
return self.db_engine_spec.get_indexes(self, inspector, table_name, schema)
|
||||
|
||||
def get_pk_constraint(
|
||||
self, table_name: str, schema: Optional[str] = None
|
||||
) -> Dict[str, Any]:
|
||||
) -> dict[str, Any]:
|
||||
with self.get_inspector_with_context() as inspector:
|
||||
pk_constraint = inspector.get_pk_constraint(table_name, schema) or {}
|
||||
|
||||
@@ -866,13 +869,13 @@ class Database(
|
||||
|
||||
def get_foreign_keys(
|
||||
self, table_name: str, schema: Optional[str] = None
|
||||
) -> List[Dict[str, Any]]:
|
||||
) -> list[dict[str, Any]]:
|
||||
with self.get_inspector_with_context() as inspector:
|
||||
return inspector.get_foreign_keys(table_name, schema)
|
||||
|
||||
def get_schema_access_for_file_upload( # pylint: disable=invalid-name
|
||||
self,
|
||||
) -> List[str]:
|
||||
) -> list[str]:
|
||||
allowed_databases = self.get_extra().get("schemas_allowed_for_file_upload", [])
|
||||
|
||||
if isinstance(allowed_databases, str):
|
||||
@@ -932,7 +935,7 @@ class Database(
|
||||
view_name: str,
|
||||
schema: Optional[str] = None,
|
||||
) -> bool:
|
||||
view_names: List[str] = []
|
||||
view_names: list[str] = []
|
||||
try:
|
||||
view_names = dialect.get_view_names(connection=conn, schema=schema)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
|
||||
Reference in New Issue
Block a user